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!

Copy a TABLE datatype into a SYS_REFCURSOR

donovan7800Dec 20 2011 — edited Dec 21 2011
Hi,

I have a procedure that has a SYS_REFCURSOR as an output parameter. This procedure has a LOOP which does some processing that creates several values that I put into a TABLE collection of a custom RECORD type. Each run through the loop, the current row is added to the table collection.

At the end of my procedure I have my collection all populated with the values already, I just need to shove this collection into a SYS_REFCURSOR.

Omitted some code for brevity:
CREATE OR REPLACE PROCEDURE LOOKUPUSER_BULK(
    p_Input     IN  SYS_REFCURSOR,
    p_Output    OUT SYS_REFCURSOR)
IS
...
    TYPE t_LicenseObject IS RECORD
    (
        Exportable          VARCHAR2(10),
        Status              VARCHAR2(30),
        License_Associated  VARCHAR2(255),
        Status_Description  VARCHAR2(255),
        License_Ind         VARCHAR2(10),
        Desc_String         VARCHAR2(255)        
    );
    TYPE t_LicenseList IS TABLE OF t_LicenseObject;
    v_OutputList    t_LicenseList := t_LicenseList();
...
AS
    BEGIN
    
        LOOP

        ....do work...

           -- Current row gets added to the existing collection here.
           v_OutputList.EXTEND(1);
           SELECT Exportable, Status, License_Associated, Status_Description, License_Ind, Desc_String
           INTO v_OutputList(v_OutputList.LAST)
           FROM DUAL;

      END LOOP;

      -- Copy into SYS_REFCURSOR here.
      OPEN p_Output FOR
      SELECT * FROM v_OutputList;
     
      -- Also tried this
      OPEN p_Output FOR    
      SELECT *
      FROM TABLE(CAST(v_OutputList AS t_LicenseList);

END LOOKUPUSER_BULK;
What is the best way to do this? Thanks.

Edited by: donovan7800 on Dec 20, 2011 9:19 AM
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 18 2012
Added on Dec 20 2011
6 comments
524 views