Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Mailing Lists -> Oracle-L -> RE: reference cursors
> -----Original Message-----
> From: oracle-l-bounce_at_freelists.org
> [mailto:oracle-l-bounce_at_freelists.org]On Behalf Of=20
> Stephen.Lee_at_DTAG.Com
>=20 >=20
I know Jonathan Lewis had some other suggestions. I am still going to = add my two cents.
Maybe I don't understand what you're trying to do, but is this what = you're looking for?
drop table t1 ;
drop table t2 ;
drop type t_tab_type ;
drop type t_type ;
drop package my_types ;
drop function f ;
create table t1 (n number, v varchar2 (30)) ;
create table t2 (n number, v varchar2 (30)) ;
insert into t1 (n, v) values (1, 'ONE') ; insert into t2 (n, v) values (2, 'TWO') ; insert into t2 (n, v) values (3, 'THREE') ;commit ;
type c_ref is ref cursor ;
end my_types ;
/
create function f (table_num_in in number)
return my_types.c_ref
is
t_data t_tab_type :=3D t_tab_type () ;
rc my_types.c_ref ;
begin
if table_num_in =3D 1
then
for t_rec in (select n, v from t1) loop t_data.extend ; t_data (t_data.count) :=3D t_type (t_rec.n, t_rec.v) ; end loop ;
for t_rec in (select n, v from t2) loop t_data.extend ; t_data (t_data.count) :=3D t_type (t_rec.n, t_rec.v) ; end loop ;
select value, name from=20 table (cast (t_data as t_tab_type)) ;return rc ;
SQL> variable x refcursor
SQL> execute :x :=3D f (1)
Proc=E9dure PL/SQL termin=E9e avec succ=E8s.
SQL> print x
VALUE NAME
--------- ------------------------------ 1 ONE
SQL> execute :x :=3D f(2)
Proc=E9dure PL/SQL termin=E9e avec succ=E8s.
SQL> print x
VALUE NAME
--------- ------------------------------ 2 TWO 3 THREE
SQL>
-- Archives are at http://www.freelists.org/archives/oracle-l/ FAQ is at http://www.freelists.org/help/fom-serve/cache/1.html -----------------------------------------------------------------Received on Fri Jan 30 2004 - 12:50:47 CST
![]() |
![]() |