Ref cursor vs sys_refcursor

What is the diffeerenece between ref cursor and sys_refcursor.in which scenarios we use ref cusor and sys_refcursor with example.For the performace point of view which is better.

BluShadow wrote:
SAMBIT RAY wrote:
Hi,
thanks for use ful difference.
i got your difference between two but as per performace level which is better.plz suggestAs billy said they are all cursors.
As my link highlights, a ref cursor of any sort is just a pointer to a query.
SYS_REFCURSOR is just a synonym for the REF CURSOR type.
There is no performance difference.Putting on my nit picking hat :-)
Sys_refcursor is a named type of type refcursor. The $ORACLE_HOME/rdbms/admin/stdspec.sql ther is this line:
/* Adding a generic weak ref cursor type */
type sys_refcursor is ref cursor;Since it is in package standard we can use it without qualifying it with a package name, but
declare
   l_cur sys_refcursor;is exactly the same as:
reate package my_pack as
   type john_cursor is ref cursor;
end;
declare
   l_cur my_pack.john_cursor;Taking off my nit picking hat now.
John

Similar Messages

  • Cursor difference (REF Cursor & Sys_Refcursor)

    Hi,
    Is there any difference between REF Cursor and SYS_Refcursor?
    I see some packages using sys_refcursor and some using REF Cursor.
    Package 1 (Spec):
       PROCEDURE s_demo1 (
          ret_rset   OUT      sys_refcursor
    Package 2 (Spec):
    TYPE cur_set IS REF CURSOR;
    PROCEDURE s_test1 (out_data OUT cur_set);
    PROCEDURE s_test2 (out_data OUT cur_set);I am going through this link (http://sql-plsql.blogspot.com/2007/05/oracle-plsql-ref-cursors.html) but didn't find the answer.

    DomBrooks wrote:
    John - don't get me wrong, I'm not suggesting that as soon as something like SYS_REFCURSOR comes along, everything should get rewritten. It's just I still see new packages written on 11g by, say mainly C# or java developers, which use this old style.
    But.... are you saying that you can't do this?
    CREATE OR REPLACE PACKAGE old_package AS
    TYPE pkg_cur IS REF CURSOR;
    FUNCTION foo(p_id IN NUMBER) RETURN sys_refcursor;
    END;
    CREATE OR REPLACE PACKAGE BODY old_package AS
    FUNCTION foo(p_id IN NUMBER) RETURN sys_refcursor IS
    l_cur sys_refcursor;
    BEGIN
    OPEN l_CUR FOR SELECT * FROM dual WHERE 1 = p_id;
    RETURN l_cur;
    END;
    END;
    Absolutely, I can even declare pkg_cursor as a sys_refcursor and all of the old calls will still work since sys_refcursor is just a ref cursor in disguise. What I cannot do is drop the declaration in the package spec since the outside callers rely on it, so since sys_refcusor is just a ref cursor in disguise, why use it?
    In fact, in OHOME/rdbms/admin/stdspec.sql which is the declarations for the package standard sys_refcursor is declared as:
      /* Adding a generic weak ref cursor type */
      type sys_refcursor is ref cursor;Since things declared in standard package (like data types, operators, all of the named exceptions etc.) are "globally" available without using the package name, sys_refcursor just provides a method to save a few keystrokes everywhere. It is no different functionally than a package declared ref cursor. The main difference is that you cannot create a strongly typed sys_refcursor, if you want/need one, you need to use a ref cursor.
    I do tend to use sys_refcursor in new code, but it took me a while to switch because there is not much real benefit as far as I can see.
    John
    Edited by: John Spencer on Nov 17, 2010 4:11 PM

  • Ref cursor returns login ids

    I have this ref cursor that returns login ids from a procedure.
    While I can define the ref cursor as sys_refcursor; I want to use strongly typed ref cursor ( for improved readabilty of code).
    But I guess I can not define the cursor that returns %type.
    e.g. Type return_login_id IS REF CURSOR return tab1.login_id%type;
    On compilation the package threw an error saying the return type should be record.
    I need to define a record with one column and use that as return type ?
    any other way around ?
    TIA
    S

    Btw, why you need to use REF Cursor?
    You can use just a cursor:
    SQL> declare
      2  cursor c1 is select empid from emp;
      3  TYPE my_id IS TABLE OF emp.empid%type;
      4  myid my_id := my_id();
      5  BEGIN
      6  OPEN c1;
      7  FETCH c1 BULK COLLECT INTO myid;
      8  CLOSE c1;
      9  END;
    10  /
    PL/SQL procedure successfully completed.
    SQL>

  • Sys_refcursor & ref cursor

    hi ,
    oracle 10.2.0.1.0
    whats the implementation difference between sys_refcursor and ref cursor ? when should one use these ? apart from knowing the fact that sys_refcursor is pre-determined weak cursor only and ref cursor could be strong or weak .
    please help .

    Simma wrote:
    Hi,
    These both are the cursor but the REF CURSOR is more restricted one, you can't return as the cursor back as we think.
    For example,
    TYPE Cursor_Ref IS REF CURSOR RETURN temp_table%ROWTYPE;
    Since the Cursor_Ref is defined as the REF CURSOR , we need to use only the colmns / fields only same as temp_table.
    As we have restricted to use temp_table%ROWTYPE;
    but in SYS_REFCURSOR, we are not restricting to any of the ROWTYPE, so it is not more restricted,
    we can return as we want.
    Edited by: Simma on Jan 11, 2011 9:22 PMYou can just writeTYPE Cursor_Ref IS REF CURSOR;
    v_cur Cursor_Ref;and this is the same asv_cur SYS_REFCURSOR;

  • Ref Cursor and For Loop

    The query below will return values in the form of
    bu     seq     eligible
    22     2345     Y
    22     2345     N
    22     1288     N
    22     1458     Y
    22     1458     N
    22     1234     Y
    22     1333     N
    What I am trying to accomplish is to loop through the records returned.
    for each seq if there is a 'N' in the eligible column return no record for that seq
    eg seq 2345 has 'Y' and 'N' thus no record should be returned.
    seq 1234 has only a 'Y' then return the record
    seq 1333 has 'N' so return no record.
    How would I accomplish this with a ref Cursor and pass the values to the front end application.
    Procedure InvalidNOs(io_CURSOR OUT T_CURSOR)
         IS
              v_CURSOR T_CURSOR;
         BEGIN
    OPEN v_CURSOR FOR
    '     select bu, seq, eligible ' ||
    '     from (select bu, seq, po, tunit, tdollar,eligible,max(eligible) over () re ' ||
    '          from (select bu, seq, po, tunit, tdollar,eligible ' ||
    '          from ( ' ||
    '          select bu, seq, po, tunit, tdollar, eligible, sum(qty) qty, sum(price*qty) dollars ' ||
    '               from ' ||
    '               ( select /*+ use_nl(t,h,d,s) */ ' ||
    '               h.business_unit_id bu, h.edi_sequence_id seq, d.edi_det_sequ_id dseq, ' ||
    '                    s.edi_size_sequ_id sseq, h.po_number po, h.total_unit tUnit, h.total_amount tDollar, ' ||
    '                    s.quantity qty, s.unit_price price,' ||
    '               (select (case when count(*) = 0 then ''Y'' else ''N'' end) ' ||
    '          from sewn.NT_edii_po_det_error ' ||
    '          where edi_det_sequ_id = d.edi_det_sequ_id ' ||
    '               ) eligible ' ||
    '     from sewn.nt_edii_purchase_size s, sewn.nt_edii_purchase_det d, ' ||
    '     sewn.nt_edii_purchase_hdr h, sewn.nt_edii_param_temp t ' ||
    '     where h.business_unit_id = t.business_unit_id ' ||
    '     and h.edi_sequence_id = t.edi_sequence_id ' ||
    '     and h.business_unit_id = d.business_unit_id ' ||
    '     and h.edi_sequence_id = d.edi_sequence_id ' ||
    '     and d.business_unit_id = s.business_unit_id ' ||
    '     and d.edi_sequence_id = s.edi_sequence_id ' ||
    '     and d.edi_det_sequ_id = s.edi_det_sequ_id ' ||
    '     ) group by bu, seq, po, tunit, tdollar, eligible ' ||
    '     ) ' ||
    '     group by bu, seq, po, tunit, tdollar, eligible)) ';
              io_CURSOR := v_CURSOR;
    END     InvalidNOs;

    One remark why you should not use the assignment between ref cursor
    variables.
    (I remembered I saw already such thing in your code).
    Technically you can do it but it does not make sense and it can confuse your results.
    In the opposite to usual variables, when your assignment copies value
    from one variable to another, cursor variables are pointers to the memory.
    Because of this when you assign one cursor variable to another you just
    duplicate memory pointers. You don't copy result sets. What you do for
    one pointer is that you do for another and vice versa. They are the same.
    I think the below example is self-explained:
    SQL> /* usual variables */
    SQL> declare
      2   a number;
      3   b number;
      4  begin
      5   a := 1;
      6   b := a;
      7   a := a + 1;
      8   dbms_output.put_line('a = ' || a);
      9   dbms_output.put_line('b = ' || b);
    10  end;
    11  /
    a = 2
    b = 1
    PL/SQL procedure successfully completed.
    SQL> /* cursor variables */
    SQL> declare
      2   a sys_refcursor;
      3   b sys_refcursor;
      4  begin
      5   open a for select empno from emp;
      6   b := a;
      7   close b;
      8 
      9   /* next action is impossible - cursor already closed */
    10   /* a and b are the same ! */
    11   close a;
    12  end;
    13  /
    declare
    ERROR at line 1:
    ORA-01001: invalid cursor
    ORA-06512: at line 11
    SQL> declare
      2   a sys_refcursor;
      3   b sys_refcursor;
      4   vempno emp.empno%type;
      5 
      6  begin
      7   open a for select empno from emp;
      8   b := a;
      9 
    10   /* Fetch first row from a */
    11   fetch a into vempno;
    12   dbms_output.put_line(vempno);
    13 
    14   /* Fetch from b gives us SECOND row, not first -
    15      a and b are the SAME */
    16 
    17   fetch b into vempno;
    18   dbms_output.put_line(vempno);
    19 
    20 
    21  end;
    22  /
    7369
    7499
    PL/SQL procedure successfully completed.Rgds.
    Message was edited by:
    dnikiforov

  • How to get values from a ref cursor in a procedure

    I have a procedure that returns a cursor type of values, but I cannot get the values.
    I got error when on how to define the output cursor. Could someone please look at the code and tell me how to correct it?
    Thanks in advance.
    ******************************8
    --This is the package
    CREATE OR REPLACE PACKAGE Test_SECURITY2 as
    type T_RoleTest is ref cursor;
    Procedure P_GetUserRole(userID in number, p_cur out T_RoleTest);
    end;
    CREATE OR REPLACE PACKAGE BODY Test_SECURITY2 as
    Procedure P_GetUserRole(userID in number, p_cur out T_RoleTest) as
    begin
         open p_cur for
         select PREO_Role.ROLE_ID,PREO_Role.ROLE_NAME
         from preorder.PREO_Role, preorder.PREO_User_Role
         where PREO_Role.Role_id = PREO_User_Role.Role_id
         and PREO_User_Role.user_id = userid;
    end;
    end;
    --This is the testing code. I got error here
    SQL> set serveroutput on;
    SQL> execute dbms_output.enable;
    PL/SQL procedure successfully completed.
    SQL> declare
    2 type T_RoleTest is ref cursor;
    3 V_UserRole is ref cursor; --how to define the output cursor
    4 v_userId number := 42;
    5 V_Role_Id number;
    6 v_Role_name varchar2(20);
    7 begin
    8 Test_SECURITY2.P_GetUserRole(v_userId, V_UserRole);
    9
    10 open V_UserRole;
    11 loop
    12 fetch V_UserRole into V_Role_Id, v_Role_name;
    13
    14 EXIT WHEN V_UserRole%NOTFOUND;
    15 dbms_output.put_line('RoleID'||v_Role_ID);
    16 dbms_output.put_line('Rolename'||v_Role_name);
    17
    18 end loop;
    19
    20 end;
    21 /
    V_UserRole is ref cursor;
    ERROR at line 3:
    ORA-06550: line 3, column 13:
    PLS-00103: Encountered the symbol "IS" when expecting one of the following:
    constant exception <an identifier>

    declare
      type T_RoleTest is ref cursor;
      v_UserRole T_RoleTest;or just:
    declare
      v_UserRole  Test_Security2.T_RoleTest;And, if you are on 9i or later, you can just use the built-in sys_refcursor type.

  • REF CURSOR in PL/SQL BLOCK

    I am trying to return a ref cursor from a function in a package. I am trying to execute this through SQL Plus and cannot seem to get the code correct this is what I have. Please help. How do I display the output? I tried a CURSOR FOR loop, but got syntactical error saying it was being used inproperly.
    DECLARE
         v_rec      adp_vsp.grc_vsp;
         v_fname ps_personal_data.first_name%TYPE;
         v_lname ps_personal_data.last_name%TYPE;
    BEGIN
         v_fname := 'John';
         v_lname := 'Barr';
         v_rec := adp_vsp.f_get_vsp(v_fname,v_lname);
    END;

    If you want to do it manually, you need to loop through the cursor and fetch the results:
    sql>create or replace procedure p_show_emps(p_rc out sys_refcursor)
      2  is
      3  begin
      4    open p_rc for select empno, ename from emp where rownum <= 5;
      5  end;
      6  /
    Procedure created.
    sql>declare
      2    v_rc     sys_refcursor;
      3    v_empno  emp.empno%type;
      4    v_ename  emp.ename%type;
      5  begin
      6    p_show_emps(v_rc);
      7    loop
      8      fetch v_rc into v_empno, v_ename;
      9      exit when v_rc%notfound;
    10      dbms_output.put_line( v_empno || ', ' || v_ename );
    11    end loop;   
    12    close v_rc;
    13  end;
    14  /
    7369, SMITH
    7499, ALLEN
    7521, WARD
    7566, JONES
    7654, MARTIN
    PL/SQL procedure successfully completed.

  • Using CRUD procedures to update data and ref cursors to return data

    Hi:
    I am currently evaluating Apex 3.x to replace an existing app that uses lots of procedures to update and return data.
    1. Is it possible to return data from a function that returns a cursor (or from a procedure that has an input/output ref cursor parameter for that matter) ? Example: Let's say I have the following function in a package:
    function get_data return sys_refcursor
    is
    l_cursor sys_refcursor;
    begin
    open l_cursor for select sysdate as field from sys.dual;
    return l_cursor;
    end;
    Can I add a page with a table that is populated based on this function? Based on my research it is not possible, but I want an APEX expert to confirm it
    2. The old application uses CRUD procedures to update date, that is for each table there are 3 procedures, insert update and delete. Question: is it possible to channel all the update, inserts and deletes through these procedures? Furthermore, in lots of cases I use sequences to populate the primary keys, and the new value is returned as output parameter. Can I retrieve the output value and use it maybe in the next page I am branching to?
    In the samples that I've seen the same form is used for insert and update. How do I distinguish between the two modes?
    3. Can you please point me to some samples that show how to do 1 & 2. The standard samples that I've seen use the automatic row processing.
    4. Could you please recommend some good books about Apex or HTML db? I found the documentation unintuitive. It is hard to picture quickly how things tie together by reading this documention. I wish the documentation was more task oriented and presented 'how to...' implement generic patterns used in web apps.
    Thank you in advance

    Hi guys
    Check out the last 2 posts in this thread for ideas on how to implement 1.
    Report on user data from LDAP
    Varad

  • Using ref cursor in where clause

    I have a stored procedure (package procedure) that returns a ref cursor as a parameter. This procedure performs a query and returns the cursor. The procedure calls another stored procedure within the package. This second procedure also returns a ref cursor. I want to do my query on the results of the cursor returned by the second procedure. Hopefully the example below is okay.. "I had to change names to protect the blah blah...."
    For example:
    TYPE out_cursor IS REF CURSOR;
    TYPE IDTable IS TABLE OF table1.ID%TYPE;
    PROCEDURE A
    v_ID IN NUMBER,
    v_Param2 IN NUMBER,
    v_FromClause IN VARCHAR2, -- ignore for now
    v_WhereClause IN VARCHAR2, -- ignore for now
    v_retval OUT NUMBER,
    the_cursor OUT out_cursor
    IS
    v_SQLString VARCHAR2(2048);
    v_cursor1 out_cursor;
    v_tabIDs IDTable;
    BEGIN
    v_SQLString := '';
    packageA.procedureA(v_ID, v_retval, v_cursor1);
    -- this does not work
    -- I get ORA-00942: table or view does not exist
    v_SQLString := 'select distinct * from v_cursor1';
    -- I found this on the message board but
    -- it did not compile.
    -- local collection types not allowed in SQL statements
    FETCH v_cTSFiles BULK COLLECT INTO v_tabIDs;
    v_SQLString := 'select distinct * from table1 WHERE table1.ID in (select * from table(v_tabIDs))';
    OPEN the_cursor FOR v_SQLString;
    END;

    You can use that second technique but as the error message says, "local collection types not allowed in SQL statements". You need to create a schema type instead.
    [sql]
    create or replace type ttab_number is table of number
    create or replace procedure p is
    tab_id ttab_number;
    refcur sys_refcursor;
    begin
    open refcur for
    select user_id
    from all_users;
    fetch refcur bulk collect into tab_id;
    close refcur;
    for rec in (
    select *
    from all_users
    where user_id in (
    select *
    from table(cast(tab_id as ttab_number)))
    ) loop
    dbms_output.put_line(rec.username);
    end loop;
    end;
    [sql]

  • Ref cursors in Database adapter

    Hi,
    Is the database adapter capable of handling ref cursors as the datatype of the output parameters of a pl/sql procedure?
    For instance if I have the following in my package-spec:
    TYPE SomeRecordType IS RECORD
    ( record_pk mut_table.record_pk%TYPE
    , person_nr person_table.person_nr%TYPE
    , field_1 mut_table.field_1%type
    , field_2 mut_table.field_2%type
    , field_3 mut_table.field_3%type
    TYPE SomeCursorType IS REF CURSOR RETURN SomeRecordType;
    PROCEDURE read_records
    ( cursor_out OUT SomeCursorType
    , exception_code OUT number
    , exception_message OUT varchar2
    Can the database adapter call the read_records procedure?
    I've never seen this in any doc. I know it can't handle record types (that is in 10.1.2 it couldn't as far as I know). So I figure that the above is not possible.
    Thanks in advance.
    Regards,
    Martien

    We have successfully used a sys_refcursor OUT parameter for a database procedure call and which is used by a DBAdapter to return a single dataset.
    At the time I remember attempting to use a strongly typed ref cursor as the parameter. I think this is what you are attempting to do. I rejected this approach at the time as I was not able to do this. It was, in our case, as simple as using the system defined ref cursor type (i.e. weakly typed).
    The handling of the returned dataset was not immediately obvious, but can be handled by as fairly simple XSL transformation to a locally defined variable of the requisite xml structure. I won't describe in detail how to do it as it is specific to our process. Suffice to say the transformation loops over all result rows assign via a test to the correct result field in our local variable.
    e.g.
    <xsl:template match="/">
    <ns1:BatchRequest004>
    <xsl:for-each select="/db:OutputParameters/db:P_SCHSHP_REF_CUR/db:Row">
    <ns1:statusRqst>
    <xsl:if test='db:Column/@name = "ID"'>
    <xsl:attribute name="id">
    <xsl:value-of select="db:Column[1.0]"/>
    </xsl:attribute>
    </xsl:if>
    </ns1:statusRqst>
    </xsl:for-each>
    </ns1:BatchRequest004>
    HTH and that I haven't misidentified your problem.

  • Is it possible to identify records in ref cursor without actually fetching

    CREATE OR REPLACE PROCEDURE test_miles (p_ref_cursor OUT SYS_REFCURSOR)
    IS
    BEGIN
    OPEN p_ref_cursor FOR
    select 5168 mem_uid, 16353 bac_uid, '2013-JAN-19' dte,3 no_of_pax,'AnoopM' username,NULL reward_id from dual
    union select 4702 mem_uid , 16344 bac_uid, '2013-JAN-29' dte, 2 no_of_pax,'RAZO' username, NULL reward_id from dual;
    END;
    Hi all,
    I have having a Procedure with out parameter as a REF CURSOR.
    This ref cursor will be returned to the calling service.
    Is there a way in oracle by which we can identify whether the Ref cursor holds data without actually fetching it.
    Since if i choose to fetch the data, i will lose one row when i return the ref cursor back to the calling service. Or else is there way i can retrieve the row i lose during fetch.
    Other alternative what have been suggested is create and object type ,fetch the ref cursor values in object type. Then i can use the ref cursor to return the data by table casting.
    one more solution is
    OPEN
    FETCH
    CLOSE
    OPEN (AGAIN)
    In reality the select statement will have is huge lines of code therefore want a suggestion whether there is an alternative to the above solution
    Please suggest.

    CREATE OR REPLACE PROCEDURE test_miles (p_ref_cursor OUT SYS_REFCURSOR)
    IS
    BEGIN
    OPEN p_ref_cursor for SELECT * from DUAL;
    OPEN p_ref_cursor FOR
    select 5168 mem_uid, 16353 bac_uid, '2013-JAN-19' dte,3 no_of_pax,'AnoopM' username,NULL reward_id from dual
    union select 4702 mem_uid , 16344 bac_uid, '2013-JAN-29' dte, 2 no_of_pax,'RAZO' username, NULL reward_id from dual;
    END;
    If the second cursor doesnt fetch any data then an empty dataset will be stored

  • Parallel  piplelined function not parallelizing with ref cursor

    RDBMS 11.2.0.3
    I have a function with the following signature
    function to_file (
      p_source     in  sys_refcursor
    , p_file_name  in  varchar2
    , p_directory  in  varchar2 default 'DD_DUMP'
    return dd_dump_ntt
    pipelined
    parallel_enable ( partition p_source by any )
    authid current_user;The function works in parallel when I use a cursor expression like this
    begin
      for rec in ( select *
                   from table(dd_dump.to_file( cursor(select /*+ parallel(i 4) */ c1||chr(9)||c2 from mytable i), 'f.out' ))
      loop
        dbms_output.put_line(rec.file_name || chr(9) || rec.num_records );
      end loop;
    end;
    f.out_162     276234
    f.out_213     280399
    f.out_230     286834
    f.out_70     289549But when I use a refcursor, it does not run in parallel
    declare
      rc sys_refcursor;
    begin
      open rc for 'select /*+ parallel(i 4) */ c1||chr(9)||c2 from mytable i';
      for rec in ( select *
                   from table(dd_dump.to_file( rc, 'f.out' ))
      loop
        dbms_output.put_line(rec.file_name || chr(9) || rec.num_records );
      end loop;
    end;
    f.out_914     1133016Is this an expected behavior or am I doing something wrong? How can I use the function when the client returns the SQL statement as a character string
    Edited by: Sanjeev Chauhan on Mar 9, 2012 11:54 AM

    Sanjeev Chauhan wrote:
    I am not performing any DML in the pipelined function. If you read the note carefuly it shows parallel_enable works only when you use:
    table(table_function(<font color=red>CURSOR</font>(select...)))and not when you use
    table(table_function(<font color=red>ref-cursor-name</font>))SY.

  • Problem with accepting the Ref Cursor in c# program

    I am passing an argument as OUT Ref Cursor in a stored procedure. and calling the procedure from my c# program.
    I can connect the database successfully but am getting the error on calling the procedure.
    I am using the ODBC connection
    My procedure's signatures are like:
    CREATE OR REPLACE PACKAGE BODY packageName
    IS
    PROCEDURE GetOutput(returnCursor OUT Sys_RefCursor)
    AS
    BEGIN
    OPEN returnCursor FOR
    <<my select statement>>
    END GetOutput;
    END packageName;
    My function call is like:
    CString Extract::ExtractScript() const
         CString script;
         script.Format("{Call %s.%s()}", packageName,GetOutput);
         return script;
    I can compile the procedure successfully on Toad but while calling the procedure from the C# program it gives following error
    Connection Successful
    Problem executing SQL {Call packageName.GetOutput()}...
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'GetOutput'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    Message was edited by:
    user653288

    Hi Aga,
    Thanks for your response.
    I figured out the problem.
    I was using the ODBC connection which wasnt updated for Oracle 10g.
    I have updated that. Now its working fine.
    Thanks again
    Regards

  • Call ref cursor functions in function also returning ref cursor?

    In 10g database, I have several functions and procedures, some packaged, that return ref cursors. These work as expected.
    Is there a way to call one or more of these in a new function and return another ref cursor?
    I know this doesn't work, but I hope it conveys the idea.
    function f_get_order_lines
       return sys_refcursor -- or defined ref cursor
    is
      v_ords orders_rcr;
      v_lines lines_rcr;
      x sys_refcursor;
    begin
      v_ords := f_get_orders;
      for rec in v_ords
       loop
        v_lines := f_get_lines;
       ... do other work here...
      end loop;
    return x;
    end;

    Pipelined table functions might do the trick for you, depending you your requirements and the transformations you need to make:
    http://download.oracle.com/docs/cd/B19306_01/appdev.102/b14261/tuning.htm#sthref2345

  • Unit Test Validation for Output Ref Cursor Not Working

    Here is the problem:
    I have a stored procedure as follows:
    CREATE OR REPLACE
    PROCEDURE usp_GetEmployee(
    p_employeeId IN NUMBER,
    cv_employee OUT Sys_RefCursor )
    AS
    BEGIN
    OPEN cv_employee FOR SELECT * FROM employees WHERE employee_id=p_employeeid;
    END usp_GetEmployee;
    For this, I am implementing a unit test.
    * In the "Select Parameters" step, I am unchecking the "Test Result" check box for the cursor OUT variable.
    * In the "Specify Validations" step, I am choosing "Boolean Function" and putting the following PL/SQL code:
    DECLARE
    emp_rec {cv_employee$}%rowtype;
    BEGIN
    FETCH {cv_employee$} INTO emp_rec;
    IF {cv_employee$}%FOUND THEN
    RETURN TRUE;
    ELSE
    RETURN FALSE;
    END IF;
    RETURN TRUE;
    END;
    But, when I try to execute this Test, I get the following error:
    Validation Boolean function failed: Unable to convert <oracle.jdbc.driver.OracleResultSetImpl@4f0617> to REF CURSOR.
    If I run in the debug mode, I get the following content in a dialog box:
    The following procedure was run.
    Execution Call
    BEGIN
    "ARCADMIN"."USP_GETEMPLOYEE"(P_EMPLOYEEID=>:1,
    CV_EMPLOYEE=>:2);
    END;
    Bind variables used
    :1 NUMBER IN 1001
    :2 REF CURSOR OUT (null)
    Execution Results
    ERROR
    CV_EMPLOYEE : Expected: [Any value because apply check was cleared], Received: [EMPLOYEE_ID                             COMMISSION_PCT                          SALARY                                 
    1001                                    0.2                                     8400                                   
    Validation Boolean function failed: Unable to convert <oracle.jdbc.driver.OracleResultSetImpl@31dba0> to REF CURSOR.
    Please suggest how to handle this issue.
    Thanks,
    Rahul

    979635 wrote:
    But, when I try to execute this Test, I get the following error:
    Validation Boolean function failed: Unable to convert <oracle.jdbc.driver.OracleResultSetImpl@4f0617> to REF CURSOR.
    If I run in the debug mode, I get the following content in a dialog box:
    The following procedure was run.
    Execution Call
    BEGIN
    "ARCADMIN"."USP_GETEMPLOYEE"(P_EMPLOYEEID=>:1,
    CV_EMPLOYEE=>:2);
    END;
    Bind variables used
    :1 NUMBER IN 1001
    :2 REF CURSOR OUT (null)
    Try explicity declaring the ref cursor instead of using a bind variable, something like (untested)
    begin
      foo sys_refcurosr;
    begin
      test_procedure(foo);
    end;Alternately, in SQL*PLUS use the DEFINE command to ste a named bind variable to type REFCURSOR and use the named bind variable in your test
    Edited by: riedelme on Jan 23, 2013 7:10 AM

Maybe you are looking for