oracle - How to output all rows in a pl/sql dynamic select without dbms_output.put_line -


i have 3 sql blocks below. first , second blocks work fine. third returns 1 row. in real world example, have 13 refcursors , each query has several columns in it. want avoid writing hundreds of dbms_out.put_line(cur.column_name) statements

--#1 correctly returns 8 rows. var rc refcursor begin open :rc select object_id,object_name user_objects rownum < 9; end; print rc --------------------------------------------------------------  --#2 correctly returns 8 rows set serveroutput on begin cur in (select object_id,object_name user_objects rownum < 9) loop     dbms_output.put_line(cur.object_id);     dbms_output.put_line(cur.object_name); end loop; end; ---------------------------------------------------------------  --#3 fail, returns 1 row set serveroutput on var rc refcursor begin cur in (select object_id,object_name user_objects rownum < 9) loop open :rc select object_id,object_name user_objects object_id = cur.object_id; end loop; end; print rc 

it's not terribly pretty, this:

var rc1 refcursor var rc2 refcursor var rc3 refcursor  begin   cur in (select object_id,rownum user_objects rownum < 4)   loop     case cur.rownum       when 1 open :rc1         select object_id,object_name user_objects         object_id = cur.object_id;       when 2 open :rc2         select object_id,object_name user_objects         object_id = cur.object_id;       when 3 open :rc3         select object_id,object_name user_objects         object_id = cur.object_id;     end case;   end loop; end; /  print rc1 print rc2 print rc3 

that works, in as multiple cursors printed out after block runs.

if on 11g perhaps have done this article suggests, via rc_to_dbms_sql procedure. i'm not sure if quite have met brief anyway, @ least automates dbms_output generation. similar dbms_sql instead of sys_refcursor, parsing inner select , still using procedure display results automatically. i'm not sure if overkill real world case though.


Comments

Popular posts from this blog

curl - PHP fsockopen help required -

HTTP/1.0 407 Proxy Authentication Required PHP -

c# - Resource not found error -