How to call Oracle Procedure which has one OUT parameter - oracle

My oracle procedure structure,
CREATE OR REPLACE PACKAGE BODY NLS_ADMIN."MY_PKG"
AS
PROCEDURE DATA_PRC (oresult OUT NUMBER )
IS
varKeyValue varchar2(1);
BEGIN
...
...
END;
I tried to call above procedure by executing below statement,
declare
oresult NUMBER;
begin
EXECUTE DATA_PRC(oresult);
end;
But getting below exception. Please help me how to call this procedure.
ORA-06550: line 8, column 9:
PLS-00103: Encountered the symbol "DATA_PRC" when expecting one of the following:
:= . ( # % ; immediate
The symbol ":=" was substituted for "DATA_PRC" to continue.

Simply this:
declare
oresult NUMBER;
begin
MY_PKG.DATA_PRC(oresult);
end;

Related

Execute PROCEDURE on Oracle PL/SQL with DECLARE variable

I just currently learning about Oracle PL/SQL. I wanna create store procedure with variable and then call it with another script. Is it possible?
I tried use simple script without variable and it works:
CREATE OR REPLACE PROCEDURE testmyproc AS
BEGIN
INSERT INTO tes_table(dt)
VALUES (sysdate);
commit;
END testmyproc;
Then I call it with another script abc.sql
begin
testmyproc;
end;
It works successfully.
But, unfortunately if I use DECLARE (variable) at my PROCEDURE, it show error when I execute (but it success in create procedure).
Here's my PROCEDURE (no error):
CREATE OR REPLACE PROCEDURE sp_testmyproc AS
DECLARE
job_name varchar(100);
status_key number;
status_desc varchar(100);
notes varchar(250);
BEGIN
status_key := 1;
status_desc := 'SUCCESS';
notes := 'Process Completed';
INSERT INTO automation_log(job_name, dt, status_key, status_desc, notes)
VALUES (job_name, sysdate, status_key, status_desc, notes);
commit;
END sp_testmyproc;
Here's my execure script abc.sql (show error when i execute it)
-without DECLARE
begin
sp_testmyproc;
end;
-I tried to execute it with DECLARE
DECLARE
job_name varchar(100);
status_key number;
status_desc varchar(100);
notes varchar(250);
begin
status_key := 1;
status_desc := 'SUCCESS';
notes := 'Process Completed';
sp_testmyproc;
end;
It show error like this:
> ORA-06550: line 8, column 11:
> PLS-00905: SP_TESTMYPROC is invalid
> ORA-06550: line 8, column 3:
> PL/SQL: Statement ignored
Can I call Procedure for another script? Is It best practice?
I just think PROCEDURE can be used for many cases (something like function in programming).
Thank you!
You need to learn the syntax of the procedure.
In Procedure, You should not use the keyword DECLARE. Any variables you want to declare must be between AS and BEGIN in the procedure.
Your procedure should look like follows:
CREATE OR REPLACE PROCEDURE sp_testmyproc AS
--DECLARE
job_name varchar(100);
status_key number;
status_desc varchar(100);
notes varchar(250);
BEGIN
status_key := 1;
.....
.....
.....
Refer to this document for the syntax of the oracle procedure as it is very easy to follow.
Please note the difference when creating a stored procedure in SQL*Plus:
SQL> create or replace procedure test_ok as
2 v number;
3 begin
4 v:=0;
5 end;
6 /
Procedure created.
SQL> show errors
No errors.
SQL> create or replace procedure test_ko as
2 declare
3 v number;
4 begin
5 v:=0;
6 end;
7 /
Warning: Procedure created with compilation errors.
SQL> show errors
Errors for PROCEDURE TEST_KO:
LINE/COL ERROR
-------- -----------------------------------------------------------------
2/1 PLS-00103: Encountered the symbol "DECLARE" when expecting one of
the following:
begin function pragma procedure subtype type <an identifier>
<a double-quoted delimited-identifier> current cursor delete
exists prior external language
SQL>
If you have compilation errors you get at least Warning: Procedure created with compilation errors. If you have compilation errors and use show errors you get all error messages.

how to create a table when value is passed in procedure in oracle?

I made a procedure which takes value and makes table which is:
create or replace procedure offc.temp(data1 varchar2(200)) is
var1 varchar2(4000);
BEGIN
var1:='create table offc.temp'||data1||'(
id number)';
EXECUTE IMMEDIATE var1;
end;
I got error when I made the procedure :
[Warning] ORA-24344: success with compilation error
1/35 PLS-00103: Encountered the symbol "(" when expecting one of the following:
:= . ) , # % default character
The symbol ":=" was substituted for "(" to continue.
(11: 0): Warning: compiled but with compilation errors
Why is this error coming as I want to create table by passing value to procedure.
You can't put the length in the parameter types
create or replace procedure offc.temp(data1 varchar2) is
var1 varchar2(4000);
BEGIN
var1:='create table offc.temp'||data1||'(
id number)';
EXECUTE IMMEDIATE var1;
end;

Call Oracle stored procedures from a main oracle stored procedure (syntax error)

I am trying to create a main Oracle stored procedure, calling other Oracle stored procedures. I am getting a syntax error in Toad.
The environment is Windows Server 2012R2 and the Oracle edition is 12.1.0.
The main stored procedure is simple:
CREATE OR REPLACE PROCEDURE TESTDB.MAIN
(
ID IN NUMBER
)
IS
BEGIN
CALL PROCEDURE1(ID);
CALL PROCEDURE2(ID);
CALL PROCEDURE3(ID);
CALL PROCEDURE4(ID);
END;
I am getting a syntax error while compiling for each procedure:
PLS-00103: Encountered the symbol "PROCEDURE1" when
expecting one of the following:
:= . ( # % ; The symbol ":=" was substituted for
"PROCEDURE1" to continue.
What is the correct syntax in order to call the procedures from one central procedure?
You have to remove CALL, that can only be used
to execute a routine […] from within SQL
BEGIN
PROCEDURE1(ID);
PROCEDURE2(ID);
PROCEDURE3(ID);
PROCEDURE4(ID);
END;
For example:
SQL> create or replace procedure proc(n IN OUT number) is begin n := 10; end;
2 /
Procedure created.
SQL> var x number
SQL> call proc(:x);
Call completed.
SQL> print :x
X
----------
10
SQL> declare
2 y number;
3 begin
4 call proc(y);
5 end;
6 /
call proc(y);
*
ERROR at line 4:
ORA-06550: line 4, column 8:
PLS-00103: Encountered the symbol "PROC" when expecting one of the following:
:= . ( # % ;
The symbol ":=" was substituted for "PROC" to continue.
SQL>

Strange PL/SQL error - PLS-00103

I have been getting a rather strange error for a long time in SQL developer.. I have stripped my package to the most basic and ran a variable declaration.. and even that is throwing an error.. this is what I am executing:
create or replace package body cdbmeta.pkg_metadata_check
is
procedure p_metadata_check(unit_id_start in number, unit_id_end in number)
is
begin
start_date NUMBER(10);
dbms_output.put_line('..');
end;
end;
and my error message states:
PLS-00103: Encountered the symbol "NUMBER" when expecting one of the following: := . ( # % ; The symbol ":=" was substituted for "NUMBER" to continue.
Totally clueless.. anyone had this before?
You have to put definition of variables after the "is" and before "begin" as follows:
create or replace package body cdbmeta.pkg_metadata_check
is
procedure p_metadata_check(unit_id_start in number, unit_id_end in number)
is
start_date NUMBER(10);
begin
dbms_output.put_line('..');
end;
end;
/
The block in procedure definition after is and before begin is the same as You would use with anonymous block like this:
declare
start_date NUMBER(10);
begin
dbms_output.put_line('..');
end;
/

Execution Error using out parameter in Oracle

begin
Num NUMBER;
EXEC GwInwForceQueueUpdateUser
('ITSC1','A07','167321','22202244333','20091103','1','110',:num);
end;
Error on line 0
begin
Num NUMBER;
EXEC GwInwForceQueueUpdateUser
('ITSC1','A07','167321','222
got Error :
ORA-06550: line 2, column 5:
PLS-00103: Encountered the symbol "NUMBER" when expecting one of the following:
:= . ( # % ;
ORA-06550: line 5, column 1:
PLS-00103: Encountered the symbol "END" when expecting one of the following:
begin function package pragma procedure subtype type use
form
current cursor
Your PL/SQL code should look like this:
declare
Num NUMBER;
begin
GwInwForceQueueUpdateUser('ITSC1','A07','167321','22202244333','20091103','1','110',num);
end;

Resources