Still unsure how to return ref cursor using dbms_sql
A reader, November 12, 2008 - 1:17 am UTC
had a look at the oracle documentation, i know how to use dbms_sql and parse cursors etc, but how does one use dbms_sql to open a ref cursor and return it to the calling program ?
whats the equivalent of
OPEN some_ref_cursor for some_variable_with_sql ;
cheers
November 12, 2008 - 10:33 am UTC
what version
Opening a cursor in oracle 10g - still not clear
Parag Gujarathi, February 13, 2009 - 9:48 am UTC
We are using a clob to store a very large query > 32K. We are not able to open a cursor to be returned to the calling program
open cursor cur for v_clob;
In 11g this is a new feature, but how do we do it in 10g? The dbms_parse package will parse and execute the query, but we need to send out a ref cursor to the calling program, is this possible?
February 16, 2009 - 11:16 am UTC
It is not possible in 10g
In 10g, best you can do is a dbms_sql cursor, you could write a pipelined function to return it as a ref cursor, but you would have to know AT COMPILE TIME how many columns there were, and their datatypes and their names. (since you have to create an object type to match the output specification of the pipelined function)
Open clob in a ref cursor
A reader, March 19, 2009 - 4:29 am UTC
Thanks for the reply. The approach you suggested was a good one (something new I came to know of :-)) but sadly it was not feasible in our case as the number of columns were variable.
We overcame this in a sort of crude way. We created the query like v_clob := 'INSERT INTO <table> ' || v_clob;
So now we are inserting data in a table and opening ref cursor as select * from <table>. Crude way and understnad that performance my be impacted a bit, but it works for now. Will have to rewrite when we move to 11g :-).
Thanks for your help.
March 19, 2009 - 10:46 am UTC
if you are using execute immediate to execute that >32k statement, it is only working by accident (if it is working) and you should rethink your approach.
you could
a) create the clob for the insert
b) break it into an array
c) use dbms_sql to parse the array of any size
but do not use execute immediate on it, your application can break at any time