Read SYS_REFCURSOR using DBMS_SQL [message #224304] |
Tue, 13 March 2007 16:36 |
Ivan
Messages: 180 Registered: June 2000
|
Senior Member |
|
|
I don't know if it's possible, but please help me if you know the answer.
I'm trying to print (read) the output of a weak ref cursor returned by a function, using DBMS_SQL package.
For example, having function:
create or replace
function f
(pin_input pls_integer)
return sys_refcursor is
rc sys_refcursor;
begin
if pin_input = 1
then
open rc for
select 'a', 'b', 'c'
from dual;
else
open rc for
select 'x', 'y', 'z'
from dual;
end if;
--
return rc;
end f;
read the content of the ref cursor, using DBMS_SQL.
I can't get to PARSE the statement. The following code won't run:
declare
c integer := dbms_sql.open_cursor;
rc sys_refcursor;
begin
dbms_sql.parse
(c => c
,statement => 'f (2)'
,language_flag => dbms_sql.native
);
--
dbms_sql.close_cursor (c => c);
exception
when others then
if dbms_sql.is_open (c => c)
then
dbms_sql.close_cursor (c => c);
end if;
--
raise;
end;
It fails with ORA-00900: Invalid SQL Statement. I understand why, but I don't see another way of coding this.
Please help, and thank you in advance.
|
|
|
Re: Read SYS_REFCURSOR using DBMS_SQL [message #224392 is a reply to message #224304] |
Wed, 14 March 2007 02:49 |
dmitry.nikiforov
Messages: 723 Registered: March 2005
|
Senior Member |
|
|
Actually it's not clear completely what exactly you want to
do.
You can use SQL*Plus connamd PRINT to show refcursor content.
Please be more specific - what do you want to achieve ?
SQL> var rc refcursor
SQL> create function f
2 return sys_refcursor
3 is
4 rc sys_refcursor;
5 begin
6 open rc for 'select ename from emp';
7 return rc;
8 end;
9 /
Function created.
SQL> exec :rc := f
PL/SQL procedure successfully completed.
SQL> print rc
ENAME
----------
SMITH
ALLEN
WARD
JONES
MARTIN
BLAKE
CLARK
SCOTT
KING
TURNER
ADAMS
ENAME
----------
JAMES
FORD
MILLER
14 rows selected.
Rgds.
|
|
|
|
|