Home » SQL & PL/SQL » SQL & PL/SQL » create stored procedure with cursor as an out argument
create stored procedure with cursor as an out argument [message #651190] Thu, 12 May 2016 09:08 Go to next message
pradeep92
Messages: 2
Registered: May 2016
Location: Merrimack, NH
Junior Member
How to create a stored procedure using cursor and stored procedure should return cursor as an out argument?
Re: create stored procedure with cursor as an out argument [message #651192 is a reply to message #651190] Thu, 12 May 2016 09:13 Go to previous messageGo to next message
pradeep92
Messages: 2
Registered: May 2016
Location: Merrimack, NH
Junior Member
declare
ref_cur sys_refcursor;
v_tab pmanrl%rowtype;
begin
dbms_output.put_line('test1');
p_test(ref_cur);
loop
fetch ref_cur into v_tab;
exit when ref_cur%notfound;
dbms_output.put_line('testttt' );
end loop;
close ref_cur;
dbms_output.put_line('test2');
end;
/





This is what I've done and it is throwing an error.
ORA- 01001









; Invalid cursor
Re: create stored procedure with cursor as an out argument [message #651194 is a reply to message #651190] Thu, 12 May 2016 09:15 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Welcome to this forum.

Please read OraFAQ Forum Guide and How to use [code] tags and make your code easier to read.

Not everything that is possible should ever be actually done.

If you were to CREATE PROCEDURE using PL/SQL, then you would win the WORST PRACTICE of the day award.

Please forget this idea ever crept into your thoughts.

Do so would be BAD, Bad, bad, VERY BAD!
Re: create stored procedure with cursor as an out argument [message #651201 is a reply to message #651192] Thu, 12 May 2016 09:58 Go to previous messageGo to next message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

Formatted:
declare
ref_cur sys_refcursor;
v_tab pmanrl%rowtype; 
begin
dbms_output.put_line('test1');
 p_test(ref_cur);
   loop
    fetch ref_cur  into v_tab;
    exit when ref_cur%notfound;
    dbms_output.put_line('testttt' );
  end loop;
  close ref_cur;
  dbms_output.put_line('test2');
end;
/

Should be posted with the SQL*Plus session like:
SQL> declare
  2  ref_cur sys_refcursor;
  3  v_tab pmanrl%rowtype;
  4  begin
  5  dbms_output.put_line('test1');
  6   p_test(ref_cur);
  7     loop
  8      fetch ref_cur  into v_tab;
  9      exit when ref_cur%notfound;
 10      dbms_output.put_line('testttt' );
 11    end loop;
 12    close ref_cur;
 13    dbms_output.put_line('test2');
 14  end;
 15  /
v_tab pmanrl%rowtype;
      *
ERROR at line 3:
ORA-06550: line 3, column 7:
PLS-00201: identifier 'PMANRL' must be declared
ORA-06550: line 3, column 7:
PL/SQL: Item ignored
ORA-06550: line 6, column 2:
PLS-00201: identifier 'P_TEST' must be declared
ORA-06550: line 6, column 2:
PL/SQL: Statement ignored
ORA-06550: line 8, column 25:
PLS-00320: the declaration of the type of this expression is incomplete or malformed
ORA-06550: line 8, column 5:
PL/SQL: SQL Statement ignored

Of course, I have not the same error than you because I have not your objects, so with any SQL or PL/SQL question post everything that is necessary for us to reproduce your case. Here the CREATE TABLE statement for "pmanrl" table and CREATE PROCEDURE for "p_test" procedure.

We can't obviously know where the error comes from without the code.
Are you able to debug code you don't see?
What we can say is that "p_test" does not set "ref_cur" or set it with an invalid value.

[Updated on: Thu, 12 May 2016 14:43]

Report message to a moderator

Re: create stored procedure with cursor as an out argument [message #651209 is a reply to message #651192] Thu, 12 May 2016 14:40 Go to previous message
Barbara Boehmer
Messages: 9090
Registered: November 2002
Location: California, USA
Senior Member
-- table:
SCOTT@orcl_12.1.0.2.0> create table pmanrl as select * from dept
  2  /

Table created.


-- stored procedure with cursor as an out argument:
SCOTT@orcl_12.1.0.2.0> create or replace procedure p_test
  2    (p_ref_cur out sys_refcursor)
  3  as
  4  begin
  5    open p_ref_cur for select * from pmanrl;
  6  end p_test;
  7  /

Procedure created.

SCOTT@orcl_12.1.0.2.0> show errors
No errors.


-- anonymous pl/sql block that calls stored procedure above and tests it:
SCOTT@orcl_12.1.0.2.0> declare
  2    ref_cur	sys_refcursor;
  3    v_tab	pmanrl%rowtype;
  4  begin
  5    dbms_output.put_line ('test1');
  6    p_test (ref_cur);
  7    loop
  8  	 fetch ref_cur into v_tab;
  9  	 exit when ref_cur%notfound;
 10  	 dbms_output.put_line ('testttt');
 11    end loop;
 12    close ref_cur;
 13    dbms_output.put_line ('test2');
 14  end;
 15  /
test1
testttt
testttt
testttt
testttt
test2

PL/SQL procedure successfully completed.


Previous Topic: Oracle Stored Procedure with Multiple Response to Calling Program
Next Topic: Execute Windows Command
Goto Forum:
  


Current Time: Thu Apr 25 18:35:05 CDT 2024