I have three sql blocks below. The first and second blocks work fine. But the third only returns one row. In my real world example, I have 13 refcursors and each query has several columns in it. I want to avoid writing hundreds of dbms_out.put_line(cur.column_name) statements
--#1 correctly returns 8 rows.
VAR rc REFCURSOR
BEGIN
OPEN :rc FOR SELECT object_id,object_name from user_objects where rownum < 9;
END;
print rc
--------------------------------------------------------------
--#2 correctly returns 8 rows
set serveroutput on
BEGIN
for cur in (select object_id,object_name from user_objects where rownum < 9)
loop
dbms_output.put_line(cur.object_id);
dbms_output.put_line(cur.object_name);
end loop;
END;
---------------------------------------------------------------
--#3 FAIL, only returns 1 row
set serveroutput on
VAR rc REFCURSOR
BEGIN
for cur in (select object_id,object_name from user_objects where rownum < 9)
loop
OPEN :rc FOR SELECT object_id,object_name from user_objects where object_id = cur.object_id;
end loop;
END;
print rc