Thanks...but,
Senthil, September 21, 2001 - 10:29 am UTC
Great answer. But i wonder is it possible to use a "Execute Immediate" in get_data function. I gave a simple query in other two functions ("fun_tab1" & "fun_tab2")...but in real time it might be having different SELECT statements...would return more than one row based on different condition. And also...the number of tables would increase and new functions will be added to it. In that case...get_data function will grow and grow further...with additional IF-THEN statements.
September 21, 2001 - 11:13 am UTC
Not with the ref cursor it isn't possible. You will get:
LINE/COL ERROR
-------- -----------------------------------------------------------------
5/2 PL/SQL: Statement ignored
5/65 PLS-00457: expressions have to be of SQL types
trying to bind a ref cursor type in dynamic SQL in PLSQL.
ref cursor with dynamic plsql table
Alok, June 11, 2004 - 11:24 am UTC
Hi sir
I'm attaching one sample code here
declare
str varchar2(32000);
str1 varchar2(32000);
a_fordnr varchar2(20);
ctr number;
TYPE REFCUR_VA IS REF CURSOR ;
va_cur REFCUR_VA;
TYPE TEMP_TAB IS TABLE OF VARCHAR2(32000) INDEX BY BINARY_INTEGER;
va_tab TEMP_TAB;
begin
va_tab(1) := 'select 1 from dual union all ';
va_tab(2) := 'select 2 from dual union all ' ;
va_tab(3) := 'select 3 from dual ' ;
open va_cur for va_tab(1)||va_tab(2)||va_tab(3);
loop
fetch va_cur into a_fordnr;
exit when va_cur%NOTFOUND;
dbms_output.put_line('Output '||a_fordnr);
end loop;
close va_cur;
exception
when others then
rollback;
dbms_output.put_line('Error '||sqlerrm);
end;
As you all noticed , that while opening the cursor i've hardcoded the all the three rows from the pl sql table.
I want a solution to add only those many rows the no of rows pl sql table is having. I can't copy in a variable and use it while opening cursor, becuase this is a sample code, actully one records size will be close to 30000 char and can't be concatenated due the limitaion of varchar2 ( 32676 ).
A help will be highly appreceaited
Alok
June 11, 2004 - 4:27 pm UTC
for i in 1 .. plsql_table_variable.count
loop
l-text := l-text || plsql-table_variable(i);
end loop;
if the sum is less than 32k -- else read about dbms_sql where you can parse an array of strings, instead of a single string.
but first -- i'd ask myself "what the HECK am i doing that would cause me to have such sql" and think (seriously) about how to do it differently.
Query
tinku, September 28, 2017 - 6:46 am UTC
What's the difference between ref cursor and native dynamic sql?
difference
tinku, September 29, 2017 - 6:57 am UTC
Thanks Chris. So, both ref cursor and native dynamic sql are same except only one difference.I mean ref cursor can return result set to the call.
Is that correct?
September 29, 2017 - 12:25 pm UTC
No!
You can open a ref cursor using native dynamic SQL. Or you could open it using static SQL.
And you can use NDS to do things other than open a ref cursor. Such as insert/update/delete.