Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to put a collection into a Ref Cursor?

637272May 2 2008 — edited May 5 2008
Hi,

I am trying to create a procedure (inside a package) which fills a collection and I need to fill a ref cursor (out parameter) with this collection. I can fill the collection but I how can I fill the ref cursor? I am receiving the message "PL/SQL: ORA-00902: invalid datatype" (Highlighted below as comments)

I have a limitation: I am not allowed to create any kind of objects at the database schema level, so I have to create them inside the package. I'm writting it with SQL Tools 1.4, I'm also not allowed to do this in SQL+.

This is the code of the package. The cursors' selects were simplified just because they are not the problem, but their structure is like follows below.

CREATE OR REPLACE PACKAGE U3.PKG_TESTE AS

TYPE REC_TYPE IS RECORD(
COL1 VARCHAR2(50) ,
COL2 VARCHAR2(100) ,
COL3 VARCHAR2(20) ,
COL4 VARCHAR2(30) ,
COL5 VARCHAR2(100) ,
COL6 VARCHAR2(50) ,
COL7 NUMBER(3) ,
COL8 VARCHAR2(30) ,
COL9 VARCHAR2(16) ,
COL10 VARCHAR2(50) ,
COL11 NUMBER(4) ,
COL12 VARCHAR2(40)
);

TYPE REC_TYPE_LIST IS TABLE OF REC_TYPE
INDEX BY BINARY_INTEGER;

TYPE C_RESULTSET IS REF CURSOR;

VAR_TAB_TESTE REC_TYPE_LIST;


PROCEDURE Z_REC_INSTANCE
(
pUSER_SYS_CODE VARCHAR2,
pSYS_SEG_CODE VARCHAR2,
pComplFiltro VARCHAR2,
pCodInter NUMBER,
cResultset out C_RESULTSET
);

END PKG_TESTE ;
/

CREATE OR REPLACE PACKAGE BODY U3.PKG_TESTE

AS

PROCEDURE Z_REC_INSTANCE
(
pUSER_SYS_CODE varchar2,
pSYS_SEG_CODE varchar2,
pComplFiltro varchar2,
pCodInter number
)

AS

cursor cur1 is
select 'A' COL1, 'B' COL2, 'C' COL3, 'D' COL4, 'E' COL5,
'F' COL6, 'G' COL7, 'H' COL8
FROM DUAL;
regCur1 cur1%rowtype;


cursor cur2 is
SELECT 'I' C1, 'J' C2, 'K' C3, 'L' C4
FROM DUAL;
regCur2 cur2%rowtype;

varSQL varchar2(4000);
varCOL10s varchar2(100);
varFiltroAtrib varchar2(100);
varCount number(10);

BEGIN
varCount := 1;

open cur1;
Loop
fetch cur1 into regCur1;
exit when cur1%notfound;

open cur2;
Loop
fetch cur2 into regCur2;
exit when cur2%notfound;

VAR_TAB_TESTE(varCount).COL1 := regCur1.COL1;
VAR_TAB_TESTE(varCount).COL2 := regCur1.COL2;
VAR_TAB_TESTE(varCount).COL3 := regCur1.COL3;
VAR_TAB_TESTE(varCount).COL4 := regCur1.COL4;
VAR_TAB_TESTE(varCount).COL5 := regCur1.COL5;
VAR_TAB_TESTE(varCount).COL6 := regCur1.COL6;
VAR_TAB_TESTE(varCount).COL7 := regCur1.COL7;
VAR_TAB_TESTE(varCount).COL8 := regCur1.COL8;
VAR_TAB_TESTE(varCount).COL9 := regCur2.C1;
VAR_TAB_TESTE(varCount).COL10 := regCur2.C2;
VAR_TAB_TESTE(varCount).COL11 := regCur2.C3;
VAR_TAB_TESTE(varCount).COL12 := regCur2.C4;

varCount := varCount + 1;

end Loop;
end Loop;

-- I'd like to do something like this:
-- c_resultset := select * from var_tab_teste;
-- but i don't know how to put the records of the type on the ref cursor,
-- probably because I don't know how to select them
-- pl/sql: ora-00902: invalid datatype

for varCount in (select COL1 from table( CAST ( VAR_TAB_TESTE AS REC_TYPE_LIST ) ))
loop
dbms_output.put('WORKS');
end loop;

END Z_REC_INSTANCE;
END PKG_TESTE;
/
SHOW ERR PACKAGE PKG_TESTE;
SHOW ERR PACKAGE BODY PKG_TESTE;
SHOW ERR PROCEDURE PKG_TESTE.Z_REC_INSTANCE;


I'm using:
Oracle9i Enterprise Edition Release 9.2.0.1.0 - Production
With the Partitioning, OLAP and Oracle Data Mining options
JServer Release 9.2.0.1.0 - Production

Thanks in advance.
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 2 2008
Added on May 2 2008
7 comments
1,528 views