Reference cursor demo
SQL>
SQL> CREATE TABLE emp (
2 id NUMBER PRIMARY KEY,
3 fname VARCHAR2(50),
4 lname VARCHAR2(50)
5 );
Table created.
SQL>
SQL> INSERT INTO emp (id, fname, lname)VALUES (1, 'A', 'B');
1 row created.
SQL> INSERT INTO emp (id, fname, lname)VALUES (2, 'C', 'D');
1 row created.
SQL> INSERT INTO emp (id, fname, lname)VALUES (3, 'Enn', 'F');
1 row created.
SQL> INSERT INTO emp (id, fname, lname)VALUES (4, 'G', 'H');
1 row created.
SQL> INSERT INTO emp (id, fname, lname)VALUES (5, 'G', 'Z');
1 row created.
SQL>
SQL>
SQL> SET SERVEROUTPUT ON ESCAPE OFF
SQL>
SQL> CREATE OR REPLACE PROCEDURE emp_sel (cv_results IN OUT SYS_REFCURSOR)
2 IS
3 BEGIN
4 OPEN cv_results FOR SELECT id, fname, lname FROM emp;
5 END;
6 /
Procedure created.
SQL>
SQL> VARIABLE x REFCURSOR
SQL>
SQL> EXEC emp_sel(:x)
PL/SQL procedure successfully completed.
SQL>
SQL> print x
ID FNAME
---------- --------------------------------------------------
LNAME
--------------------------------------------------
1 A
B
2 C
D
3 Enn
F
4 G
H
5 G
Z
5 rows selected.
SQL>
SQL> drop table emp;
Table dropped.
SQL>
Related examples in the same category