I have kind of a tricky Oracle problem. I am trying to select one set of data, we’ll call items. For each item I want to call another procedure and return an Inventory Item. I have two operations I am not sure on how to perform.
-
How do I retrieve a value from the nested procedure?
-
How do I return those retrieved values in the form of SYS_REFCURSOR?
My attempt here was to put the results from spSelect_Inv_Search into a nested table called ITEMS_TABLE. This is not working.
Code below
PROCEDURE SPSELECT_ITEM (IO_CURSOR OUT SYS_REFCURSOR)
AS
MY_CURSOR SYS_REFCURSOR;
TYPE ITEM_TYPE IS TABLE OF ITEMS.ITEM_NO%TYPE;
ITEM_TABLE ITEM_TYPE := ITEM_TYPE();
CURSOR ITEMS_CURSOR IS
SELECT ITEM_NO
FROM ITEMS;
V_COUNTER INTEGER := 0;
BEGIN
FOR ITEM_REC IN ITEM_CURSOR LOOP
V_COUNTER := V_COUNTER + 1;
ITEM_TABLE.EXTEND;
ITEM_TABLE(V_COUNTER) := spSelect_Inv_Search(ITEM_REC.ITEM_NO, MY_CURSOR);
END LOOP;
END SPSELECT_ITEMS;
Any help is appreciated, thanks.
You seem to be wanting to merge an unknown number of
SYS_REFCURSORresult sets into one big one. If you know the structure of the cursor returned fromspSelect_Inv_Searchyou can do this with an intermediate pipelined function.The types can be defined here, they don’t have to be at SQL level as you won’t ever need to reference them outside the package.
Then to execute, which you can do outside the package despite the types used for the intermediate stage, you can do this to test in SQL*Plus or SQL Developer:
For my database this gives:
This is obviously very contrived as you’d do this as a single query, but I’m assuming your inner procedure needs to do something more complicated.