What does "IS" do in Oracle procedures? - oracle

I want to create a procedure in Oracle; however, any sample that I look on the internet, has an "IS" syntax, which I couldn't find any functionality for it.
CREATE [OR REPLACE] PROCEDURE procedure_name
[ (parameter [,parameter]) ]
IS
[declaration_section]
BEGIN
executable_section
[EXCEPTION
exception_section]
END [procedure_name];
Does anyone know what does "IS" do?

IS is part of Create procedure syntax: (can be replace with AS)
It separate the procedure definition from its contents.
The optional declaration section that follows allows you to declare local variables.

IS, in this context, tells us (and the compiler) that what follows is the body of the procedure. Its absence tells us (and the compiler) that it is merely a declaration (e.g. a forward declaration in a package body):
create or replace package body mypkg is
-- this is just a forward declaration for the procedure
procedure myproc (id in number);
-- this is the full definition of the procedure
procedure myproc (id in number)
IS
..body of myproc..;
end mypkg;
In the case of a schema-level procedure, we could (in theory) have a syntax that makes the IS optional since there is no need for forward declarations; but (thankfully) the designers of PL/SQL kept the syntax consistent with the in-package syntax so IS is still required anyway.

Related

Not recognizing the record type parameter of a stored procedure

I am trying to test a newly created stored procedure in Oracle.
I added the stored procedure to the package and successfully compiled it. The input parameter is a record type.
This is the script:
SET serveroutput on;
DECLARE
p_trlr_rec trailer%ROWTYPE;
BEGIN
/* Call procedure within package, identifying schema if necessary */
TMS_SL_SQL_TRAILER.PR_UPDATE_DUE_INFO(p_trlr_rec);
END;
I get the error:
PLS-00306: wrong number or types of arguments in call to 'PR_UPDATE_DUE_INFO'
In the package file, the parameter is defined like this:
PROCEDURE PR_UPDATE_DUE_INFO
(p_rec IN OUT rectype_trailer);
PROCEDURE PR_UPDATE_DUE_INFO
(p_rec IN OUT rectype_trailer);
I also tried adding the TYPE definition:
PROCEDURE PR_UPDATE_DUE_INFO
(p_rec IN OUT rectype_trailer);
but I get the same error.
Why won't the script recognize the record definition?
Well the script is recognizing your record definitions, both of them. The calling routine is passing a parameter of type "trailer%ROWTYPE" but your procedure is expecting a type of "rectype_trailer" Even if "rectype_trailer" is defined elsewhere they are not the same; thus the error is wrong type of argument.
You need to change one of them to match the other. Assuming the rowtype definition is correct you need to change the procedure definition to
PROCEDURE PR_UPDATE_DUE_INFO
(p_rec IN OUT trailer%ROWTYPE);
In short the calling parameter definition must exactly match the called procedure definition.
PROCEDURE PR_UPDATE_DUE_INFO
(p_rec IN OUT rectype_trailer);
So for this to compile you must have declared that record type somewhere, hopefully in the specification of the package TMS_SL_SQL_TRAILER. So you simply need to reference that declaration in the calling code:
DECLARE
p_trlr_rec TMS_SL_SQL_TRAILER.rectype_trailer;
BEGIN
/* Call procedure within package, identifying schema if necessary */
TMS_SL_SQL_TRAILER.PR_UPDATE_DUE_INFO(p_trlr_rec);
END;
Oracle PL/SQL strictly enforces data typing. Two different types with identical structures are two different types and the compiler regards them as incompatible. So the compiler hurls when it tries to parse your calling code even if TMS_SL_SQL_TRAILER.rectype_trailer is declared as being of trailer%ROWTYPE.

What to use for input parameter when debugging Oracle Stored Procedure using TOAD debugger

I inherited an awesome 600 line Stored Procedure in which I need to debug. I'm trying to debug by right clicking on the name of the stored procedure, clicking execute using sql debugger. This brings up a table in which I can manually enter my parameters. Great. Except one of the parameters is a OracleArray vArray INPUT parameter, and I'm not sure how to actually enter something like this as a parameter? I'm not familiar with Oracle.
Your question doesn't have a lot of details, so I'll have to give a vague answer. Here's how you can call a procedure (named other_procedure) which takes a VARRAY argument or other complicated setup. Once you've declared a test procedure, you can execute it with the debugger and then step into the procedure you actually care about.
CREATE OR REPLACE PROCEDURE test_procedure IS
-- (size and type of the varray should match the one in other_procedure)
TYPE my_array_t IS VARRAY(4) OF VARCHAR2(20);
-- define and initialize your array
test_array my_array_t := my_array_t('one','two','three');
BEGIN
-- call the procedure
other_procedure(test_array);
END;
/
If you're still having trouble, edit your question to provide more details (like the procedure definition and varray definition) and we can give a more specific answer.

Optional output cursor as parameter

I'm trying to cater for two applications.
One calls a procedure with 2 cursors, the other with 1.
Both are OUT SYS_REFCURSOR.
Because of the difference in definition of the procedure, the change to one application will break the other.
I am wondering if its possible to have the same procedure with both OUT SYS_REFCURSOR but with the second parameter as optional. This is done in other parts of the project by defining a default value.
I have tried googling and defining default values but to no avail. This doesnt seem to be a very common issue.
Is there a way to have this definition with an optional OUT SYS_REFCURSOR ?
Here is my code:
PROCEDURE Proc_GetQ (qList OUT SYS_REFCURSOR, qStack OUT SYS_REFCURSOR);
I would like qStack to be optional.
Thanks,
JFIT
What about method overloading?
PROCEDURE Proc_GetQ (qList OUT SYS_REFCURSOR, qStack OUT SYS_REFCURSOR);
PROCEDURE Proc_GetQ (qList OUT SYS_REFCURSOR);
Create a procedure with the same name, similar logic (better call 2-parameter version inside and pass only one outside), but only one OUT parameter.

oracle plsql: retrieve runtime parameter values when you call a procedure

I need a generalized method to get list of runtime parameters (values) when I call a procedure. I need something similar to the $$PLSQL_UNIT that returns the name of the running procedure.
(plsql Oracle 10g)
E.g. look at this sample procedure:
(it simply prints its own name and parameters )
CREATE OR REPLACE PROCEDURE MY_PROC(ow in varchar2, tn IN varchar2)
IS
BEGIN
dbms_output.put_line('proc_name: '||$$PLSQL_UNIT||' parameters: '|| ow||' '||tn );
EXCEPTION
WHEN OTHERS THEN
DBMS_OUTPUT.PUT_LINE('ERRORE: ' ||SQLERRM);
END MY_PROC;
/
Running procedure produces the following output:
SQL>
1 BEGIN
2 IBAD_OWN.MY_PROC('first_par', 'second_par');
3 END;
4 /
proc_name: MY_PROC parameters: first_par second_par
PL/SQL procedure successfully completed.
I'm not satisfy because I can't copy and paste in all my procedures because I have to hard code each procedure to set their right parameter variables.
Thanks in advance for the help.
It isn't possible to dynamically retrieve the values of parameters passed to a procedure in Oracle PL/SQL. The language simply isn't designed to handle this kind of operation.
Incidentally, in a procedure that is located within a package, $$PLSQL_UNIT will only return the package's name. I find it's better to define a consistently-named constant within each procedure that contains the procedure's name.
When I wanted the same functionality as yours I didn't find any good built-in solution.
What I did is: wrote DB-level trigger which modifies original body of function/procedure/package.
This trigger adds immediatly after "begin" dynamically generated piece of code from "user_arguments".
Plus, after that I include into this trigger the code, that logs calls of procs when exception occures.
Plus, you can trace procs calls, and many more interisting things.
But this solution works fine only for preproduction because performance decreases dramatically.
PS. Sorry for my bad English.

What is the difference between "AS" and "IS" in an Oracle stored procedure?

I see Oracle procedures sometimes written with "AS", and sometimes with "IS" keyword.
CREATE OR REPLACE Procedure TESTUSER.KILLINSTANCE (INSTANCEID integer) **AS**
...
vs.
CREATE OR REPLACE Procedure TESTUSER.KILLINSTANCE (INSTANCEID integer) **IS**
...
Is there any difference between the two?
Edit: Apparently, there is no functional difference between the two, but some people follow a convention to use "AS" when the SP is part of a package and "IS" when it is not. Or the other way 'round. Meh.
None whatsover. They are synonyms supplied to make your code more readable:
FUNCTION f IS ...
CREATE VIEW v AS SELECT ...
One minor difference...
They are synonyms for packages and procedures, but not for cursors:
This works...
cursor test_cursor
is
select * from emp;
... but this doesn't:
cursor test_cursor
as
select * from emp;
"IS" and "AS" act as a synonym while creating procedures and packages but not for a cursor, table or view.
Here's another difference (in 10g, at any rate)
Given a loose object type:
CREATE TYPE someRecordType AS OBJECT
(
SomeCol VARCHAR2(12 BYTE)
);
You can create a loose Table type of this object type with either AS or IS
CREATE OR REPLACE TYPE someTableType
IS {or AS} TABLE OF someRecordType;
However, if you create this same table type within a package, you must use IS:
CREATE OR REPLACE PACKAGE SomePackage IS
TYPE packageTableType IS TABLE OF someRecordType;
END SomePackage;
Use of AS in the package yields the following error:
Error(2,30): PLS-00103: Encountered the symbol "TABLE" when expecting one of the following: object opaque
According to TutorialsPoint
The AS keyword is used instead of the IS keyword for creating a
standalone procedure.
and considering previous answers,
I guess
AS is for stand alone (outside of any block, subprogram, package) entities
and
IS is for embedded (within a block, subprogram or package) entities.
.
The AS keyword is used instead of the IS keyword for creating a standalone function.
[ A standalone stored function is a function (a subprogram that returns a single value) that is stored in the database.
Note: A standalone stored function that you create with the CREATE FUNCTION statement is different from a function that you declare and define in a PL/SQL block or package. ]
For more explanation, read this...

Resources