I need to have stored procedure where I can run multiple cursors.
Loop over each cursor and then do some operation on each row.
This way I will have the desired result from these cursors. Result of such multiple cursors then needs to be union with some other rows and then filtered out and return those rows finally from the proc.
Please note that each cusror and another queries will have same columns.
I am not sure how to do this in the oracle.
Please help me out.
create or replace PROCEDURE test_proc
(
-- some inputs
hc_cursor OUT SYS_REFCURSOR
)
IS
cursor cursor_one is
SELECT * FROM table_one ;
BEGIN
FOR current_row in cursor_one
loop
-- do some modification on each row and return each modified row
end loop;
cursor cursor_two is
SELECT * FROM table_one ;
BEGIN
FOR current_row in cursor_two
loop
-- do some modification on each row and return each modified row
-- append to result from first cursor
end loop;
-- union results from both these cusrors with some another query
-- now filter these records on some criterais
-- return finally
END;
My suggestion is going to be insert the rows from your cursor into a temporary table. Then join the temporary table with your existing table for the filter criteria you mention. Psuedocode:
As you have seen the code,what i do ,is to get the desired result in
nested table
(what your cursor is doing) ,and do some manipulation based on the resultant records ,as well as update the nested table.At the end i will create a cursor from this
updated nested table
and return the cursor after opening.Now your question :
How can you return append cursor
?It is simple
create two nested table ,do some manipulation on both the nested table
Suppose you have
v_emp_nt1
asfirst nested table
,you do some manipulation on that . you have anotherv_emp_nt2
assecond nested table
,you do some manipulation on that .Now your
cursor
will be likeWith this way you can achieve your desired output .
**Note:**The above code is for one nested table ,you need to create another nested table for your code to get complete