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!

BULK COLLECT in select query inside a function

890271Apr 18 2013 — edited Apr 18 2013
Hi All,

My query is :

SELECT col1,col2,col3 FROM table_a; --( consider this is a long running query with lot of joins)

Need to know how can i get the output of the above query from a function using BULK COLLECT.


and i tried this:

CREATE OR REPLACE TYPE tab_a_row
AS OBJECT (
col1 number(20),
col2 number(20),
col2 number(20)) ;

create or replace type tab_a_nt as table of tab_a_row;

create or replace function get_table_a
return sys_refcursor
is

tab_a_recs tab_a_nt;
rv sys_refcursor;

begin

SELECT tab_a_row(col1,col2,col3) BULK COLLECT INTO tab_a_recs FROM table_a;

open rv for select * from table(tab_a_recs);
return rv;

end;
/
Function created successfully. and i exec this from sql plus using

SQL> var rc refcursor;
SQL> exec :rc := get_table_a;
BEGIN :rc := get_table_a; END;

*
ERROR at line 1:
ORA-22905: cannot access rows from a non-nested table item
ORA-06512: at "GET_TABLE_A", line 12
ORA-06512: at line 1


Kindly share your ideas on how to use bulk collect and get set of outputs from a function.

Edited by: 887268 on Apr 18, 2013 3:10 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on May 16 2013
Added on Apr 18 2013
7 comments
906 views