How to display REF_CURSOR out Parameter from a procedure -Oracle12C

101 Views Asked by At


Am i doing anything wrong here , i am trying to display the SYS_REFCURSOR out values in DBMS_OUTPUT. here is my code so far, its giving invalid cursor exception . can someone help me on this .
DECLARE
out_dcursor SYS_REFCURSOR;
snumber                     VARCHAR2(5);
   inumber                 VARCHAR2(15);

BEGIN

 my_proc(out_dcursor, 'INPUT_VALUE', NULL, NULL, NULL,NULL, NULL, NULL, NULL, NULL,'INPUT_VALUE2', NULL, NULL);
 
 loop
 fetch out_dcursor into snumber
           ,inumber;
 exit when out_dcursor%NOTFOUND;
 end loop;
 
END;
1

There are 1 best solutions below

5
Littlefoot On

You're complaining about dbms_output and invalid cursor, but - there's no first term in code you posted, and you didn't say which part returns the second one.

Here's example which shows something that works. See if you can use it with your code, as we don't know what my_proc is, accepts, does nor returns.

SQL> create or replace procedure my_proc (par_rc out sys_refcursor) is
  2  begin
  3    open par_rc for select deptno, dname from dept;
  4  end;
  5  /

Procedure created.

SQL> set serveroutput on;
SQL> declare
  2    rc       sys_refcursor;
  3    l_deptno dept.deptno%type;
  4    l_dname  dept.dname%type;
  5  begin
  6    my_proc(rc);
  7    loop
  8      fetch rc into l_deptno, l_dname;
  9      exit when rc%notfound;
 10      dbms_output.put_Line(l_deptno ||' '|| l_dname);
 11    end loop;
 12  end;
 13  /
10 ACCOUNTING
20 RESEARCH
30 SALES
40 OPERATIONS

PL/SQL procedure successfully completed.

SQL>