Home » SQL & PL/SQL » SQL & PL/SQL » Loop after fetch on generic SYS_REFCURSOR (11.2.0.1.0)
Loop after fetch on generic SYS_REFCURSOR [message #676170] Sun, 19 May 2019 01:17 Go to previous message
OraFerro
Messages: 433
Registered: July 2011
Senior Member

Hi All,

I have a procedure that returns a SYS_REFCURSOR out of a general select that is not based on a specific table where I can generate a type using %Type.
I want to return both the result cursor and also an aggregation (example number of rows in the below procedure). However I fail to generate an array of SYS_REFCURSOR to use it in the FETCH before looping.

I need help to know what I am missing and/or dont know in order to avoid repeating the select again to get the aggregate result.



CREATE OR REPLACE  PROCEDURE P_GET_DATA_TEST
  ( 
    I_NUM     IN NUMBER, 
    CUR_REF   OUT SYS_REFCURSOR, 
    I_TOTAL_ROWS OUT NUMBER  
  )
  AS
    TYPE ARY_ARRAY IS TABLE OF SYS_REFCURSOR;
    AR_MY_ARRAY ARY_ARRAY;
    
  BEGIN
  

    OPEN CUR_REF FOR 
    SELECT  ROWNUM 
    FROM ALL_OBJECTS
    WHERE ROWNUM <= i_num ;

   I_total_rows:=0;

   FETCH CUR_REF BULK COLLECT INTO ar_My_Array;
   FOR I IN 1..ar_My_Array.COUNT LOOP
   I_total_rows := I_total_rows + 1;
   END LOOP;

/*
I want to avoid:
    OPEN CUR_REF FOR 
    SELECT  count(ROWNUM ) into I_total_rows 
    FROM ALL_OBJECTS
    WHERE ROWNUM <= i_num ;
*/

   CLOSE CUR_REF;    


  END;
 
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Read Message
Previous Topic: Error: ORA-00980: synonym translation is no longer valid
Next Topic: minus query using dblink
Goto Forum:
  


Current Time: Thu Apr 25 20:15:04 CDT 2024