我在下面有三个 sql 块。第一个和第二个块工作正常。但第三个只返回一行。在我的真实示例中,我有 13 个 refcursor,每个查询都有几列。我想避免编写数百个 dbms_out.put_line(cur.column_name) 语句
--#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