Bạn sẽ sử dụng REF CURSOR như một con trỏ rõ ràng thông thường :
SQL> CREATE TABLE employee AS
2 SELECT rownum id, 'XXX' name
3 FROM DUAL CONNECT BY level <= 10;
Table created.
SQL> CREATE OR REPLACE PROCEDURE find_employees (
2 emp_id NUMBER,
3 employee_cursor OUT SYS_REFCURSOR
4 ) IS
5 BEGIN
6 open employee_cursor for
7 select * from employee WHERE id = emp_id;
8 END;
9 /
Procedure created.
SQL> CREATE OR REPLACE PROCEDURE do_something IS
2 cc sys_refcursor;
3 l employee%rowtype;
4 BEGIN
5 find_employees(1, cc);
6 LOOP
7 FETCH cc INTO l;
8 EXIT WHEN cc%NOTFOUND;
9 dbms_output.put_line(l.id||'-'||l.name);
10 END LOOP;
11 END;
12 /
Procedure created.
SQL> EXEC do_something;
1-XXX