Passing Ref Cursor as IN parameter

I have a situation where I have to send whole table into the stored procedure, I read from the oracle new feature for .Net documentation, It is possible to pass an ref cursor as IN parameter to an stored procedure. Please help me in this, it is urgent!
I am using Visual Studio.Net 2003, ODP.Net.

Array binding is the best method for large inserts from .NET.
The problem with the associative array is:
-you must write a PL/SQL procedure to actually do the inserts.
-while this will get the data to the PL/SQL engine on the server in a block, it still must cross the into the SQL engine one row at at time.
-Array binding is simpler (you use a normal insert).
-There's a built-in knob to control the batch size.
-The array of row data is copied all the way into the SQL engine together, so it's faster.
Remember, array binding is how the SQL*Loader's conventional-path inserts work.
According to Tom Kyte "you can achive 100's of rows per second into heavily indexed tables that are concurrently being read and updated by other processes."
David

Similar Messages

  • Problem in passing ref cursor values as parameter in where clau.Most Urgent

    Problem:
    1) I have used normal cursor (C_hubmsgid_set) with some select statement such as grouping and all.
    After executing the query it will return some resultset to the specified cursor.
    2) I am trying to use another cursor which is ref cursor but the problem is
    I want to give all the resultset based on all the conditions to the ref cursor.
    But the cursor will get only the last record due to overwriting .how to get all
    the result set in a ref cursor like
    cursor c1 is select .....
    loop
    open refcursor for
    Select * from ....where condition
    end loop
    After this the refcursor( p_sysaudithistory_cur) which should have all the resultset matched by the where condition.
    3. It should be java compatible one.
    4. I am not able to match cursor row = IN Pameter value
    Below is the query:
    CREATE OR REPLACE PROCEDURE SP_TEST_audit_history2 (
    p_start IN date,
    p_end IN date,
    p_msgcode IN varchar2,
    p_partnername IN varchar2,
    p_status IN varchar2,
    p_locationname IN varchar2,
    p_custbusunit IN varchar2,
    p_sysaudithistory_cur OUT plutotypes.ref_cursor,
    p_status1 OUT NUMBER) AS
    l_status NUMBER := 0;
    CURSOR C_hubmsgid_set IS
    SELECT DISTINCT MAX(tfm.datetime) datetime, tfm.hubmsgid
    FROM tfm_status tfm, vw_msgcode_part_locn vw
    WHERE
    tfm.datetime >= NVL(p_start, TO_DATE('01/01/1981','DD/MM/YYYY')) AND
    tfm.datetime <= NVL(p_end, TO_DATE('31/12/9999','DD/MM/YYYY')) AND
    tfm.msgcode LIKE NVL(p_msgcode,'%') AND
    vw.msgcode = tfm.msgcode
    AND vw.partnername LIKE NVL(p_partnername,'%')
    AND tfm.status LIKE NVL(p_status,'%')
    AND vw.locationname LIKE NVL(p_locationname,'%')
    AND vw.custbusunit LIKE NVL(p_custbusunit,'%')
    AND rownum < 250
    GROUP BY tfm.hubmsgid
    ORDER BY datetime DESC;
    /* Loop through the Cursor */
    BEGIN
    BEGIN
    OPEN p_sysaudithistory_cur
    FOR
    SELECT
    tfm.hubmsgid ,
    tfm.status || '-'|| nvl2(tfm.exception_id,'FAILED','OK') ,
    tfm.datetime,
    tfm.exception_id
    FROM tfm_status tfm
    WHERE tfm.hubmsgid = c_hubmsgids.hubmsgid /* here only i am getting error*/
    AND tfm.datetime = c_hubmsgids.datetime
    AND tfm.status like NVL(p_status,'%')
    and rownum =1;
    EXCEPTION
    WHEN NO_DATA_FOUND
    THEN
    l_status := 1;
    END;
    p_status1 := l_status;
    END;
    Thanks in advance
    prasanth a.s.

    Please don't post duplicate questions. All it does is clutter the forums and result in fragmented threads and duplicate responses. Please see my response in the original thread at the link below.
    Please solve this Refcursor issue PLEASE

  • Passing Ref Cursor as parameter to object type method

    I am encountering a problem passing a parameter of type REF CURSOR to methods of a set of object types I am developing.
    Here is an example of what I am trying to do:
    create or replace package p1 as
    type c_Cursor is ref cursor;
    end p1;
    create or replace type t_Object as object
    not instantiable method m1(p_Cursor in p1.c_Cursor) return varchar2
    ) not instantiable not final;
    create or replace type t_Subtype under t_Object as
    overriding method m1(p_Cursor in p1.c_Cursor)
    return varchar2
    The problem is that the PL/SQL compiler gives the error message PLS-00201 "p1.c_Cursor" not defined.
    According to my PL/SQL book (SF's Oracle PL/SQL Programming) the only way to use a ref cursor as a parameter to functions/procedures is to wrap them in a package. Indeed I have developed a test procedure in a different package that uses p1.c_Cursor as a parameter and it works fine.
    Oracle's documemtation suggests that object security (roles etc) can cause this error but as all the objects are being created in the same schema I don't see how this should be a problem.
    If anyone can suggest how to get around this problem I will be very grateful.
    BTW, if there are any mistakes in my sample code it's because I am writing it from memory as I don't have Internet access at work.
    Thanks,
    Charles.

    Thanks for your reply. I am still baffled as to why it doesn't work but, as you correctly point out, SYS_REFCURSOR works just fine. I figured that out earlier today and now the problem is solved.
    Charles.

  • REF Cursor as Job Parameter

    Hi,
    is it possible to use a REF cursor as a parameter for a job? I need jobs created with DBMS_SCHEDULER.create_job to process data which has always the same format but comes from different sources. The job must be generic and thus should not know where the data comes from. The job calls a PL/SQL procdure which takes the REF cursor as a parameter.
    Regards,
    Pat
    Edited by: Gwydion on Jun 16, 2010 7:13 AM

    Gwydion wrote:
    I tried a different way: Instead of a ref cursor, I tried to pass a PL/SQL table containing the data that the job should process. Bad idea in general as this is not very scalable. A PL/SQL "+table+" is nothing table-like at all. The correct term is array or collection. This structure is primitive in that it cannot be indexed or structured like a SQL table. It also resides in "expensive" memory (the PGA/private memory of a server process) - unlike a SQL table data that will reside in the SGA buffer cache when used. The db buffer cache is shared memory - usable by all processes and thus "inexpensive" memory in comparison.
    So passing and processing any largish data structure that way (via PGA memory) is inherently an unscalable approach. Also, this data set needs to persist until the job process kicks off - thus it needs to be stored somewhere. Why store this data again when it is based on table and row table that already exist in the database? Why duplicate the data?
    You also need to consider data concurrency and integrity. By the time that job/scheduler background process kicks off and receives this data set structure to use for processing... the row data that this set was based on may have changed.. or may not even exist anymore.
    For example, let's say that the data set contains a list of invoice numbers that need to be processed. Some of those invoices may have been canceled in the meantime. Or deleted from the system. Whatever invoice numbers this background server process now needs to deal with, can now be invalid.
    You therefore need to carefully consider exactly what issues and requirements you're trying to address with this approach you are attempting. There are numerous problems areas that it needs to deal with.
    Which begs the question - why are you considering this approach? What problem are you trying to address? Why not simply pass the parameters to the job it needs to use to call the procedure that creates the ref cursor? This is a much simpler and elegant solution than to pass the actual data returned by the ref cursor to the job.

  • Ref Cursor as input parameter

    Is it possible to pass a ref cursor from java as an input parameter to a stored procedure, which the procedure can then process?
    (Passing Ref Cursors as output parameters from a stored procedure to a result set works fine.)

    You may want to try passing Arrays to the Stored Procedure. Use Oracle.SQL.ARRAY and then in the stored procedure get the array.

  • REF CURSOR as IN parameter to stored procedure

    Currently, ODP.NET supports REF CURSOR parameter as OUT parameter only.
    Based on the project requirements it is necessary to pass
    multiple records to the stored procedure.
    In this case REF CURSOR as IN parameter is useful.
    What are the plans to implement REF CURSOR as IN parameter to stored procedure?
    What is the work around in case it is necessary to pass several different
    record types as arrays to stored procedure?

    ODP.NET does not limit REF Cursor parameters to IN parameters. This is a known PL/SQL limitation.
    An excerpt from Application Developer's Guide:
    "If you pass a host cursor variable to PL/SQL, you cannot fetch from it on the server side unless you also open it there on the same server call".

  • Using ref cursor in after parameter form in reports

    hi everyone,
    I have problem in usage of ref cursor in after parameter form. My actual requirement is I have user parameter :p_minval, :p_maxval. The values into these user parameters will be coming dynamically using sql_statement as shown below
    select min(empid),max(empid) into :p_minval, :p_maxval from emp where empid in (:p_emp);
    I will be writing this query in the after parameter form
    :p_emp is a lexical parameter as per me but the after parameter form is taking it as a bind variable. so I decided to define a ref cursor and then use it for retrieve. But when I use ref cursor it is returning pl/sql error 591 saying that this is not supported by client side can anyone help me plz..
    The following is the code i tried to use in after parameter form
    function afterPform return boolean is
    type rc is ref cursor;
    l_rc rc;
    sqlstmt varchar2(512);
    begin
    sqlstmt:='select min(empid),max(empid) from emp where empid in ('||:p_emp||')';
    open l_rc for
    select max(empid) from emp where empid in ('||:p_emp||')';
    fetch l_rc into :p_maxval;
    close l_rc;
    return(true);
    end;
    thanks & regards
    venkat

    I ran into the same problem. any body knows why?

  • Problem passing REF CURSOR to JAVA STORED PROCEDURE

    Hi,
    I've written a small Java class with a static method and
    imported that into Oracle 8i. The method expects a
    java.sql.ResultSet object as parameter. According to the
    documentation of Oracle, a REF CURSOR (cursor variable) maps to
    java.sql.ResultSet in JDBC.
    The definition of the Java Stored Procedure was accepted without
    problems:
    CREATE OR REPLACE PROCEDURE RESULTSETPASSINGTESTPROC (row
    WASTypes.GenericCurType)
    as language java
    name 'sqlj.ResultSetPassingTest.testResultSetPassing
    (java.sql.ResultSet)';
    WASTypes is a package containing the definition of the generic
    cursor:
    CREATE OR REPLACE PACKAGE WASTYPES
    is
    TYPE GenericCurType IS REF CURSOR;
    END WASTypes;
    In a function I'm opening the cursor via
    'Open cursorVariable for sqlStatement';
    Then this cursor variable is passed to the java method and the
    error ORA-03113 is shown.
    I tried to solve the problem by changing the type of the
    parameter to oracle.sql.REF without success.
    Does anybody know what wents wrong?
    Thanks in advance.
    Jan

    Hi,
    I've written a small Java class with a static method and
    imported that into Oracle 8i. The method expects a
    java.sql.ResultSet object as parameter. According to the
    documentation of Oracle, a REF CURSOR (cursor variable) maps to
    java.sql.ResultSet in JDBC.
    The definition of the Java Stored Procedure was accepted without
    problems:
    CREATE OR REPLACE PROCEDURE RESULTSETPASSINGTESTPROC (row
    WASTypes.GenericCurType)
    as language java
    name 'sqlj.ResultSetPassingTest.testResultSetPassing
    (java.sql.ResultSet)';
    WASTypes is a package containing the definition of the generic
    cursor:
    CREATE OR REPLACE PACKAGE WASTYPES
    is
    TYPE GenericCurType IS REF CURSOR;
    END WASTypes;
    In a function I'm opening the cursor via
    'Open cursorVariable for sqlStatement';
    Then this cursor variable is passed to the java method and the
    error ORA-03113 is shown.
    I tried to solve the problem by changing the type of the
    parameter to oracle.sql.REF without success.
    Does anybody know what wents wrong?
    Thanks in advance.
    Jan

  • How to pass a cursor as IN parameter to a procedure

    Hello
    I want to pass a cursor to a procedure as IN parameter.
    See the below piece of code:
    Cursor mycur is select * from table_name;
    Procedure myproc(mycur IN ...)
    begin
    fetch mycur into v_rec;
    {want to do some updates here}
    end;
    Please suggest how can I pass the cursor?
    Thanks in advance !!!!

    793059 wrote:
    I want to pass a cursor to a procedure as IN parameter.You can use the PL/SQL type called sys_refcursor - and open a ref cursor and pass that to the procedure as input parameter.
    Note that the SQL projection of the cursor is unknown at compilation time - and thus cannot be checked. As this checking only happens at run-time, you may get errors attempting to fetch columns from the ref cursor that does not exist in its projection.
    You also need to ask yourself whether this approach is a logical and robust one - it usually is not. The typical cursor processing template in PL/SQL looks as follows:
    begin
      open cursorVariable;
      loop
        fetch cursorVariable bulk collect into bufferVariable limit MAX_ROWS_FETCH;
        for i in 1..bufferVariable.Count
        loop
          MyProcedure( buffer(i) );   --// <-- Pass a row structure to your procedure and not a cursor
        end loop;
        ..etc..
        exit when cursorVariable%not_found;
      end loop;
      close cursorVariable;
    end;

  • Passing Ref Cursor to Oracle Stored Procedure Via C#

    Hi all,
    I am new to oracle and stuck with an issue. I have three insert stored procedures for three different tables. Two of them have multiple rows to be inserted, which is currently done via iterating through each row and insert to db in C# code. My requirement is to merge these three procedures in one and instead of iterating from C# code send table rows as (ref cursor or collection) to procedure and the procedure will handle the rest.
    I read that ref cursor only works if you're data is in database as it reference the memory but in my case data is build on client side.
    I am using Oracle 11i and ASP.Net 2.0
    Can any help me on this please?
    Edited by: 929463 on Apr 23, 2012 12:38 AM

    929463 wrote:
    I am new to oracle and stuck with an issue. I have three insert stored procedures for three different tables. Two of them have multiple rows to be inserted, which is currently done via iterating through each row and insert to db in C# code. My requirement is to merge these three procedures in one and instead of iterating from C# code send table rows as (ref cursor or collection) to procedure and the procedure will handle the rest.Why a single procedure? How is the procedure to determine the target table to insert the data into? And please - no dynamic SQL as that is 99% of the time wrong.
    A ref cursor is something that PL/SQL creates - with the purpose of passing the cursor handle to your code. This enables the actual SQL statement for that cursor to be moved from client code, into a PL/SQL stored proc. It abstracts the client from having to understand SQL, understand the data model and so on. All clients use the same PL/SQL proc and thus the same code for creating that cursor. Thus no issue of some clients getting it half right or half wrong and dealing with data inconsistencies between clients.
    The PL/SQL proc can be tuned and optimised, modified for catering for data model changes and so on. Without your client code having to be even recompiled as it is isolated against these server changes.
    For all other interaction (running PL/SQL code, doing insert/update/delete/etc SQL statements), you need to create the cursor yourself in your code.
    Also, the SQL engine only sees cursors. There are no differences between cursors. The client (e.g. PL/SQL) can call it a reference cursor, or an implicit cursor, or a DBMS_SQL cursor.. the SQL engine does not know that and does not care.
    A ref cursor is simply a special type of client interface to a SQL cursor, allowing PL/SQL to create that SQL cursor and then pass the handle of that SQL cursor to other code to consume that cursor.
    Okay, so if you want to insert data, you need in your code to create a cursor. This can be a SQL INSERT cursor - the actual insert statement. Or it can be a PL/SQL call - an anonymous PL/SQL code block that calls a stored proc that performs the insert (after applying validation and business logic).
    The cursor will have one or more bind variables. Your client will pass values for these variables and the server-side code (SQL or PL/SQL) will be executed using this as variable data.
    You can for example create a cursor as follows:
    begin
      DoFunkyInsert( :1, :2, :3 );
    end;
    {code}
    3 bind variables are expected. You can now in the client build an array for each of these variables, containing a 100 values each (total of a 100 rows to insert). Do a single execute of the cursor, and tell Oracle that the bind is actually a 100 element array.
    The complete array ships to Oracle - Oracle opens a loop and execute the cursor for each element in the array.
    This is called bulk binding.
    An alternative approach is to define the bind variable as a collection (a non-scalar value). And then code the PL/SQL procedure to open a loop and iterate through the collection/array, inserting a row per iteration.
    The binding itself is more complex as your code know needs to understand Oracle object types and be able to define an array/collection that is a valid Oracle non-scalar data type.
    The +Oracle Call Interface+ (OCI) is quite flexible in this regard. However, as you work via an abstraction layer (e.g. ADO, OleDB, ODBC, etc) your code is subject to whatever functionality this abstraction layer makes available to your code. And this is seldom includes all the power, functionality and flexibility of the (more complex) OCI itself.                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                           

  • Pass REF CURSOR to Procedure and LOOP through it

    Hi All,
    I am trying to figure out how I can pass a ref cursor to a procedure and then loop through it. I have provided an example of what I am attempting to do...just not really sure how to open the ref cursor when it is passed ot the sproc and iterate through it?
    Any info would be greatly appreciated.
    Version:
    Oracle Database 10g Enterprise Edition Release 10.2.0.3.0 - 64bi
    PL/SQL Release 10.2.0.3.0 - Production
    CORE     10.2.0.3.0     Production
    TNS for Linux: Version 10.2.0.3.0 - Production
    NLSRTL Version 10.2.0.3.0 - Production
    Create Or Replace Package test_ref_pkg
    AS
    function get_ref_curs
    RETURN SYS_REFCURSOR;
    procedure process_ref_curs(
    p_ref_cursor        IN  SYS_REFCURSOR
    END test_ref_pkg;
    Create Or Replace Package Body test_ref_pkg
    AS
    function get_ref_curs
        RETURN SYS_REFCURSOR
    IS
        l_ref_curs      SYS_REFCURSOR;
    BEGIN
        OPEN l_ref_curs FOR
        Select 1 ID, 'Test 1' Name
        From DUAL
        UNION ALL
        Select 2 ID, 'Test 2' Name
        From DUAL;
    END get_ref_curs;
    procedure process_ref_curs(
    p_ref_cursor        IN  SYS_REFCURSOR
    IS
    BEGIN
        ---NOT SURE WHAT TO DO TO ITERATE THROUGH THE REF CURSOR I AM PASSING INTO THIS SPROC?----
    END process_ref_curs;
    END test_ref_pkg;Thanks,
    S
    Edited by: ScarpacciOne on May 28, 2010 9:11 AM

    ---NOT SURE WHAT TO DO TO ITERATE THROUGH THE REF CURSOR I AM PASSING INTO THIS SPROC?----
    -- MAYBE I AM SIMPLE, BUT HOW ABOUT FETCH???
    -- if you start to yell, I will yell too!!!!
    Sybrand Bakker
    Senior Oracle DBA

  • How to pass a CURSOR as an input in a Stored Procedure ?

    Hi all
    I am using Java to work with 2 Oracle DBs, using JDBC.
    I've got a question about using a Oracle Stored Procedure with CURSORs :
    A first stored procedure gets data from the first DB (returns a CURSOR) and I'd like to pass this CURSOR to the second stored procedure as a (Java) IN parameter, so using a "getObject()" then a "setObject()", to insert data from the CURSOR in the second DB.
    This is the theory !
    En reality, the first stored procedure works fine, and returns the cursor, but after that ... I can't even create the second stored procedure. I planed to do something like the following stuff :
    CREATE OR REPLACE PROCEDURE proc_insert_data(cur_ref IN OUT types.ref_cursor) AS
    BEGIN
    LOOP
    FETCH cur_ref INTO FIELD1, FIELD2;
         INSERT INTO TABLENAME VALUES (FIELD1, FIELD2);
    EXIT WHEN cur_ref%NotFound;
    END LOOP;
    END proc_insert_data;
    with a LOOP for each row and then an INSERT.
    But this doesn't seeem to be correct.
    Has anybody an idea to make this stored procedure to work ?
    Thx in advance
    Krystoffff

    Hi Chris,
    When you want to pass a CURSOR to a procedure/function
    you will have to employ a package here. Create a package
    which contains both of your procedures.This package should have a global variable which is of type ref cursor.The IN parameter for the 2nd procedure and the OUT parameter of the first proc should be of type this global cursor var.
    Now you call the first procedure and get the resulting cursor from it, pass it to the second procedure...
    Good luck.
    Regards,
    Madhu

  • Open ref cursor in a procedure

    Hi
    I have a procedure which has 3 input parameters and 1 REF CURSOR type OUT parameter.
      In the body of the procedure a select query is dynamically being created, and just before the end of the procedure the REF CURSOR is opened for SELECT(dynamic) query
    For Ex: Create or replace procedure proc_name(a in number,b in number,c in number,RETVAL OUT REF CURSOR) as
    decalre
      strQry varchar2(3000);
    begin
       -- strQry is select query built dynamically
    OPEN RETVAL for strQry;
    end proc_name;
    This procedure is being called by a java application. My question is what the open cursor statement is doing in the procedure?
    Any ideas? Thanks!
    greddy

    Hi,
    As i know, for example if we want to generate a report for some particular records in our project.consider we are using java as front end and oracle as backend. ok. In that case we need to bring the data from backend to front end ,for that in backend (oracle) we can write procedure to perform this task using ref cursors.
    Note: ref cursor will provide the most efficient way in bringing the records from back end to front end.
    Create or replace procedure proc_name(a in number,b in number,c in number,RETVAL OUT REF CURSOR) as
    decalre
    strQry varchar2(3000);
    begin
    -- strQry is select query built dynamically
    --if we are using dynamic query, we can filter out the records using id or name or date
    once we did, we need to pass the values to calling enviroment, since we declared the ref cursor as out parameter, we can use the ref cursor to pass the values to calling enviroment. Since we are using ref cursor we need to open the cursor for that dynamic query.
    OPEN RETVAL for strQry;
    end proc_name;
    hope this information is some what helpful. if you got any details regarding this please post it..
    thanks.

  • Using Ref Cursor in procedure in place of normal cursor

    Hi,
    I have a procedure where i have the follwoing cursors declared,
    CURSOR c_wip IS
    SELECT tdvalue
    FROM tabledetails
    WHERE tdidcode = 'PEL_DASHBOARD'
    AND tdkey LIKE 'WIP_QUEUES%';
    CURSOR c_pending IS
    SELECT tdvalue
    FROM tabledetails
    WHERE tdidcode = 'PEL_DASHBOARD'
    AND tdkey LIKE 'PENDING_QUEUES%';
    CURSOR c_out IS
    SELECT tdvalue
    FROM tabledetails
    WHERE tdidcode = 'PEL_DASHBOARD'
    AND tdkey LIKE 'OUT_QUEUES%';
    CURSOR c_out_status IS
    SELECT tdvalue
    FROM tabledetails
    WHERE tdidcode = 'PEL_DASHBOARD'
    AND tdkey LIKE 'OUT_STATUS%';
    Will the usage of 1 ref cursor instead of the 4 cursors increase the performance.
    Thanks.

    Cursor is a structure which points to a memory locations.
    While a Ref-cursor is a datastructure which point to a object which inturn points to Memory locations.
    The advantage of having Ref-cursor is that we can pass dynamically the Ref-cursor as a parameter to a procedures.
    So it does improve the performance to a small extent.

  • Trouble with Bulk Collect to Ref cursor

    I'm trying to open a ref cursor to a dynamic query, and the fetch the cursor (BULK COLLECT)to the table type variable.But I keep getting the compilation error as 'PLS-00597: expression 'EMP_RESULTSET' in the INTO list is of wrong type'
    But when I use a simple select from a table and Bulk Collect directly to the table type variable it works. But that is not what I want.
    Can someone tell me where I have gone wrong in this stored proc I have listed below.
    your help will be highly appreciated.
    PROCEDURE SP_TEST_EMP_TABLE_TYPE (
          p_resultset OUT result_cursor          -- ref cursor as out parameter
       AS
        TYPE TYPE_REC_EMP is RECORD(EMPNO EMPLOYEE.EMPNO%TYPE, JOIN_DATE EMPLOYEE.JOIN_DATE%TYPE, SALARY EMPLOYEE.SALARY%TYPE); -- declare record type
        TYPE TYPE_TAB_EMP IS TABLE OF TYPE_REC_EMP;    -- declare table type
        EMP_RESULTSET TYPE_TAB_EMP; -- declare variable of type type_calendar_avail_resultset  
        SQUERY VARCHAR2(32000):='';
       BEGIN
        SQUERY:='SELECT EMPNO,JOIN_DATE,SALARY FROM EMPLOYEE WHERE EMPNO= 1001 AND JOIN_DATE=''20070530'' ';
        --select EMPNO,JOIN_DATE,SALARY BULK COLLECT INTO EMP_RESULTSET from  EMPLOYEE WHERE EMPNO=1001 AND JOIN_DATE='20070525';
        OPEN p_resultset FOR SQUERY;
          FETCH p_resultset BULK COLLECT INTO EMP_RESULTSET;
      EXCEPTION
          WHEN NO_DATA_FOUND
          THEN
             NULL;
          WHEN OTHERS
          THEN
             DBMS_OUTPUT.put_line (SQLERRM (SQLCODE));   
       END SP_TEST_EMP_TABLE_TYPE ;

    > i) I use a ref cursor to return back to the java
    front end, so I had to use a ref cursor.
    What is a ref cursor? It is not a data set. It is a pointer to a "SQL program". This program is created by the SQL Engine and the CBO that parses the SQL source code and determine an execution plan to get to the requested rows.
    When the client fetches from a (ref) cursor, the client is running this program and it find and returns the next row.
    There is no such thing as a physical result set for a cursor - no "copy" of the rows found for the source code SQL is made as a result set.
    > ii) I also use a dynamic sql, but I was thinking it
    wasn't useful for this posting, so tried to write a
    simple sql
    What is dynamic SQL? SQL where object names (e.g name of the table) is only known at run-time. Or where the filter (e.g. WHERE conditions) can only be determined at run time.
    If these are known, the SQL is static SQL.
    For both static and dynamic SQL, bind variables are critical. It is the biggest performance mistake (in Oracle) to hardcode values and literals into a SQL.
    > ii) I use a Bulk Collect to the table type
    collection, since I use a loop, for which I had to
    collect the results from each loop and finally send
    the resultset thru the ref cursor.
    Impossible. Nor does it make any sense. As stated, a ref cursor is a program and not a result set.
    What you intend to do is run a SQL against data. Copy this data into private/local PL/SQL memory. Construct another SQL against this data - which means that it needs to be shipped back to the SQL engine as it cannot use/read local PL/SQL memory structures. And the pass that SQL cursor to the client.
    What for?
    > I had earlier used the logic to for this using a
    temporary table, which works perfectly fine, but our
    DBA says we should avoid temporary tables since it
    makes additional read/write to the disk. This is the
    reason I'm using table type collection here.
    Your DBA is correct. One should so a single pass through a data set. Which is why simply passing a ref cursor for a SQL statement to the client is the simplest.
    It makes no sense copying SQL data into a collection and then copying that back into the SQL engine in order to throw a ref cursor around it.
    Basic client-server fundamentals.
    And why RTFM the Oracle manuals I've indicated is important. You need to understand the memory and processing architectures in Oracle in order to make an informed and correct decision.

Maybe you are looking for

  • Windows Vista Installed, Can't Get Drivers, Won't Read 10.4.8 Install Disk

    Hello. I've searched the forums and haven't found an answer yet. I installed Windows Vista 32-bit using Boot Camp on my Mac Pro. That part was fine but I cannot get the drivers to load from my install disk (10.4.8). This is a totally legit copy. The

  • Condition type JMOP

    Hi Gurus,                Accidentally one condition type JMOP with val 16%was deleted and was put back date. So in PO we are not geting JMOP. When i go to FV12 or FV13 i cant see that deleted condition type as new condition type with 14% was created

  • Not use foreign keys.

    I would like to know if is it bad if I don't want to use foreign keys? is it just a constraint? Is it useful? If I wont use delete on cascade for example is it mandatory to use foreign keys? Please help me with this doubt. Thanks.

  • Display dimming, then brightening quickly

    Title says it all. Machine is a mid-2009 15" MBP, OS X 10.6.7. Energy Saver settings are: Battery: Computer sleep: 10 minutes Display sleep: 2 minutes SSD sleeps when possible, and the display is set to dim on this power source and to reduce its brig

  • IMac sometimes won't switch off

    I trust this is the Yosemite discussion... In general, my iMac, vintage late 2007 with an SSD installed has responded well to the installation of Yosemite. The only problem is that, at times, when I want to shut down the computer, it closes some prog