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".

Similar Messages

  • Problem calling a ref cursor that is in a stored procedure

    I have a stored procedure that returns a ref cursor as follows and I want to call it from another procedure in the same package. It compiles, but when I run it, it gets errors.
    procedure procGetRefCursor(p_string in varchar2, p_int in integer, p_return out sys_refcursor) AS
    l_subrefcursor l_refcursor;
    begin
    open l_subrefcursor for
    SELECT myval
    FROM mytab a
    WHERE myval1 = p_string;
    end procGetRefCursor;
    The following code compiles, but when I run it it errors out on the fetch.
    ERROR at line 1:
    ORA-01001: invalid cursor
    I also tried opening the cursor first and that does not compile. I also tried
    fetch p_return.myval in l_myval
    that does not compile
    procedure callGetRefCursor(p_string in varchar2,p_int in integer) is
    p_return sys_refcursor;
    l_myval varchar2(100);
    begin
    procGetRefCursor(p_string, p_int, p_return);
    loop
    fetch p_return into l_myval;
    dbms_output.put_line('myval '||l_myval);
    exit when p_return%notfound;
    end loop;
    end;

    Where is l_refcursor defined?
    And why?
    Aren't you using SYS_REFCURSOR?

  • 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.

  • 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

  • Passing parameter into stored procedure

    Hi guys,
    I have a big problem here passing as a parameter in stored
    procedure.
    If i pass as a parameter in where clause it is working fine.
    Whenever i pass the parameter in order by it was not working..
    How to implement this issue????
    Here i am giving the example for package:
    PACKAGE XTRA.TEST_STATUS
    AS
    TYPE GenericCurTyp IS REF CURSOR;
    PROCEDURE SP_MAIN
    ( insortgroup IN VARCHAR2,GENERAL_CUR IN OUT GenericCurTyp);
    END TEST_STATUS;
    PACKAGE BODY XTRA.TEST_STATUS
    AS
    PROCEDURE SP_MAIN
    ( insortgroup IN VARCHAR2, GENERAL_CUR IN OUT GenericCurTyp
    ) AS
    BEGIN
    OPEN GENERAL_CUR FOR
    select last_name,first_name from applicant Order By insortgroup;
    END SP_MAIN;
    END TEST_STATUS;
    Passing as a parameter i am getting the below details.
    LAST_NAME FIRST_NAME
    ASFSDAF DASDFASF
    Ad DASD
    Adams John
    DANA WITEST
    If i hot code the parameter insortgroup to last_name
    i am getting the below values:
    LAST_NAME FIRST_NAME
    'ANNUNZIO GIANCOLA GABRIEL
    0'BRIEN ARMA
    0120453EZ ESTANISLAO
    082479 ELIZABETH
    Thanks,
    Rao

    CREATE OR REPLACE PACKAGE xtra.test_status
    AS
      TYPE GenericCurTyp IS REF CURSOR;
      PROCEDURE sp_main
        (insortgroup IN     VARCHAR2,
         general_cur IN OUT GenericCurTyp);
    END test_status;
    CREATE OR REPLACE PACKAGE BODY xtra.test_status
    AS
      PROCEDURE sp_main
        (insortgroup IN     VARCHAR2,
         general_cur IN OUT GenericCurTyp)
      AS
        select_statement VARCHAR2 (4000) := NULL;
      BEGIN
        select_statement :=
        'SELECT   last_name,
                  first_name
         FROM     applicant
         ORDER BY ' || insortgroup;
        DBMS_OUTPUT.PUT_LINE (select_statement);
        OPEN general_cur FOR select_statement;
      END sp_main;
    END test_status;

  • Pass a date parameter to Stored Procedure

    Hello friends,
    Can you help to pass a date parameter to Stored procedure from JSP. This is my code:
    In Oracle 9i I have this:
    PROCEDURE SP_EDORES(
    pfechaini IN hist_pol_reclama.hrc_fecha_contabilidad%Type, <-- This is a date field
    pfechafin IN hist_pol_reclama.hrc_fecha_contabilidad%Type, <-- This is a date field
    p_recordset OUT PKG_REP_CIERRE.cursor_type) AS
    In JSP have this:
    CallableStatement stmt = (CallableStatement)conn.prepareCall( "begin PKG_REP_CIERRE.SP_EDORES(?,?,?); end;" );
    stmt.registerOutParameter(3,oracle.jdbc.driver.OracleTypes.CURSOR);
    stmt.setDate(1,Date.valueOf("01-06-2005"));
    stmt.setDate(2,Date.valueOf("30-06-2005"));
    ResultSet rset = (ResultSet)stmt.getObject(3);
    while (rset.next()) {
    %>
    <TR>
    <TD ALIGN=CENTER> <%= rset.getString(1) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getString(2) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getString(3) %> </TD>
    <TD ALIGN=CENTER> <%= rset.getInt(4) %> </TD>
    </TR>
    <%
    The Stored Procedure returns de Result set, however I think does not recognized the date format because I need it with this format dd-mm-yyyy.
    Thanks in advance

    to use Date you will need the oracle package.
    u can try this other solution: use String, not Date
    CallableStatement stmt = (CallableStatement)conn.prepareCall( "begin PKG_REP_CIERRE.SP_EDORES(?,?,?); end;" );
    stmt.registerOutParameter(3,oracle.jdbc.driver.OracleTypes.CURSOR);
    stmt.setString(1,"01-06-2005");
    stmt.setString(2,"30-06-2005");
    ResultSet rset = (ResultSet)stmt.getObject(3);
    while (rset.next()) {
    %>
    if this don't work you can change your PL/SQL to get Strings and do the conversion with TO_DATE in the sql statement.

  • 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;

  • 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?

  • Return a parameter through stored procedures

    Hello Experts
    I want to return parameter through stored procedures so as to ensure that the application has been executed properly.
    My source message format is
    <StatementName5>
    <storedProcedureName action=u201D EXECUTEu201D>
      <table>Summarize_prc</table>
    <empid  [isInput=u201Dtrueu201D] [isOutput=true] type=SQLDatatype>val1</empid>
    </storedProcedureName > 
    </StatementName5>
    Do i need to put some extra parameters for return values from the stored procedures?
    What would be the response message format to return the parameters from stored procedure.
    Thanks
    Sabyasachi

    Hi,
    If you wants to read the return values from stored procedure, the scanario should be designed as Sync.
    The format looks like thsi
    <Message Type Name>
          <STATEMENTNAME_response>
                      <Field1> </Field1>
       </STATEMENTNAME_response>
    </Message Type Name>

  • Is it possible to pass TABLE as the output parameter in stored procedure

    Hey Experts,
      Is it possible to pass TABLE as the output parameter in stored procedure.
    eg
    create procedure spGetData
    @tableName as TABLE(intValue INT NOT NUL)
    as 

    You can use OPENQUERY or OPENROWSET, as mentioned above, to make stored procedure results table like. There are
    some limitations with these methods:
    http://technet.microsoft.com/en-us/library/ms188427.aspx
    In OPENQUERY this-sql-server-instance can be used instead of a linked server name. It requires setting data accces server option:
    exec sp_serveroption @server = 'PRODSVR\SQL2012'
    ,@optname = 'DATA ACCESS'
    ,@optvalue = 'TRUE'
    LINK: http://www.sqlusa.com/bestpractices/select-into/
    Kalman Toth Database & OLAP Architect
    SELECT Video Tutorials 4 Hours
    New Book / Kindle: Exam 70-461 Bootcamp: Querying Microsoft SQL Server 2012

  • 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.

  • Rowtype parameter in stored procedure

    Hi,
    Trying to call a stored procedure/function in C++ using OCI libs, with ROWTYPE parameter. Any ideas on how to do this?
    Thanks!

    You can't.
    ROWTYPE is an internal-to-PLSQL-only datatype (like BOOLEAN) except there is no external data type mapping. Use REF CURSOR or scalar arrays or object arrays instead.

  • So many Input parameter in stored procedure..how to handle it ?

    Hello,
    I have one stored procedure.in that,there is around *600 input parameter*.now I am writing one by one input parameter and this is looking very time consuming for me.is there any other method to solve it.can we use Ref cursor or any thing else...??if yes,then please explain me with one example....I have no so much idea about ref cursor.
    Thanks

    It would be pretty stupid, in any language, to define a method/procedure/function that has a 600 parameter signature.
    There are a number of ways to address this - correctly. And these have already been suggested:
    - define proper data structures for these parameters
    - use arrays
    As for how to address this in PL/SQL, depends entirely on how the call interface from the client looks like and is capable of.
    For example, if this is from a web page and the call is made via mod_plsql, the flexible 2 parameter call interface should be used. The procedure will have 2 parameters. The caller will pass name-values. The 1st array will contain the names (e.g. 600 names). The 2nd array will contain the values (e.g. 600 values).
    If the caller is a Java for example, then advance user define/custom SQL types can be defined in Oracle, used and populated in Java, and then pass to PL/SQL.
    Let's say the caller is pretty dumb and does not support the object features in the OCI (OCI = the Oracle client driver call interface used by the client).
    In that case you do not want a 600 parameter procedure.. but you still need to get the data into that Oracle server session in order to execute PL/SQL code in that session to crunch that data. A flexible and scalable solution would be to define a GTT - a global temp table (done once off up front in that schema). This allows the client to insert rows in that temp table that can be seen by that session's PL/SQL code only. For performance, the client can create a standard client array for the 600 parameters and call the SQL insert using array binding.
    This results in a single insert call to Oracle. Accompanied with 600 values. Oracle executes that insert 600 times. You know have 600 rows in the GTT and the next client call to Oracle instructs the PL/SQL procedure to process the contents of the GTT.

  • Passing parameter in stored procedure

    Hi, I am really new to using Oracle stored procedure. I have just tested a sample stored proc which should return multiple rows without passing any parameter.
    here is the stored proc I wrote
    create or replace procedure get_address
    as
    cur_table sys_refcursor;
    begin
    open cur_table for
    select * from address_table order by addr_id;
    end;
    when I execute it, I get a message "Procedure Created"
    then I executed the stored proc
    exec get_address;
    I again get a message "PL/SQL procedure successfully completed" and I do not see the records at all.
    so I decide to rewrite to the stored proc as such
    create or replace procedure get_address(cur_table out sys_refcursor)
    as
    begin
    open cur_table for
    select * from address_table order by addr_id;
    end;
    everthing is good so far.
    now when execute it
    exec get_address;
    I am getting the following error:
    "PLS-00306: wrong number or types of arguments in call to 'TESTCODEPROC'"
    I have searched so many places, but there is no document talks about this issue. I hope someone can help me to over come this. I need to call this stored proc from .NET 2.0 reporting viewer which is embedded in asp.net page.
    Thank you.

    so I decide to rewrite to the stored proc as such
    create or replace procedure get_address(cur_table out
    sys_refcursor)
    as
    begin
    open cur_table for
    select * from address_table order by addr_id;
    end;
    everthing is good so far.
    now when execute it
    exec get_address;
    I am getting the following error:
    "PLS-00306: wrong number or types of arguments in
    call to 'TESTCODEPROC'"
    From what you wrote I can assume that you have used SQL server before. Oracle does not automatically return the last opened cursor from a stored procedure like the query result, so you cannot just call exec get_address; (or just execute the procedure from .NET code). You will have to pass the cursor parameter and fetch it as an output parameter value in .NET, then use it to get the data reader etc.
    On the other hand, you can just execute the statement directly. I see a lot of folks coming from SQL server world using stored procedures like crazy even for things that are naturally suited to queries and views. Oracle view allows you to apply the same security restrictions you can put onto a stored procedure, and if you use statement caching and bound variables, you get precompilation benefits as well with a view. Using a view instead of a procedure in this case will require less code both in the database and in .NET, and will give you a more flexible interface in terms of retrieved columns and ordering.
    gojko adzic
    http://gojko.net

  • Datetime parameter from stored procedure

    <p>I have a report written in CR10 which uses a stored procedure as the datasource. The stored procedure has 3 input parameters, two of which are datetime data types. When the crystal report is run, it prompts the user for the 3 parameters & runs just fine except...</p><p>For the date parameters, it prompts the user to enter a time as well. In previous versions of Crystal, parameters that were datetime data types in the stored procedure were just prompted for the date when the calling crystal report was run.</p><p>I attempted to edit the parameters in the report, but the "Value Type" is grayed out (I assume since the parameter is associated with the stored procedure, rather than being a user defined parameter within the report).  These date parameters are used in a BETWEEN statement in the stored proc, so if the user just enters a date but accepts the default time, the returned data gets flakey due to the addition of the time value passed by the parameter.</p><p> I tried setting a default value for the time, but I have to enter a date along with the time, which the report then uses as the default. The user then has to uncheck the "Pick from defaults" checkbox in order to enter their own date. This is really unwieldly for the end user, especially when they were previously able to just enter a date and not have to be concerned with a time at all.</p><p>Does anyone have suggestions on working around this issue? </p><p>Thanks in advance...</p>

    <p>You mention that you are using CRW version 10 for this.  What&#39;s the data source you are reporting against (you mention a stored procedure - but are you running against Oracle, SQL Server, DB2?).  Are you connecting natively or using ODBC? <br /></p>

Maybe you are looking for