Populate temp table from ref cursor
804855Oct 28 2010 — edited Oct 29 2010Hello,
I have 3 tables like below, for the simplicity I showed only the necessary columns
TABLE_1(ID1, FILTER_1, FILTER_2) primary key: ID1
TABLE_2(ID1, ID2) primary key: ID1 and ID2
TABLE_3(ID1, ID2, ID3) primary key: ID1, ID2 and ID3
I have also temporary tables:
TABLE_1_TEMP and TABLE_2_TEMP
The ID1's are all same in 3 tables, and the ID2's are all same in 2 tables.
I want to return 3 ref cursors from my stored procedure.
PI_FILTER_1 IN NUMBER,
PI_FILTER_2 IN NUMBER,
REF_CURSOR_1 OUT T_CURSOR,
REF_CURSOR_2 OUT T_CURSOR,
REF_CURSOR_3 OUT T_CURSOR
REF_CURSOR_1 will contain the filtered rows of TABLE_1 based on a number of optional parameters like FILTER_1, FILTER_2.
So I write something like that.
OPEN REF_CURSOR_1 FOR dynamic_query using PI_FILTER_1, PI_FILTER_2;
First question: how can I populate TABLE_1_TEMP from the REF_CURSOR_1 so that I can use it in the following query
OPEN REF_CURSOR_2
SELECT * from TABLE_2 WHERE ID1 IN (SELECT ID1 FROM TEMP_TABLE_1)
Then I want to populate TEMP_TABLE_2 from REF_CURSOR_2, and use it for the REF_CURSOR_3
Second question: can I do this without using temp tables but without any duplicate select statements.