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.

Similar Messages

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

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

  • 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

  • Cursor like input parameter in function

    Hi, All !
    I have a question. I want use cursor like input parameter in function. How can I do this? Please give my an example.

    in fact i have a loop over a cursor :
    LOOP
    tmp_var:=0;
    FETCH contrat_cursor INTO contrat_rec;
              EXIT WHEN contrat_cursor%NOTFOUND;
    treatment1 -- i want to put all this trt1 in a function , and the function , since it depend on contrat_rec, will have a parameter
    end loop;
    in other context i need this function to make some trt in one row of the table contrat
    so i can get this row with select * from contrat where ...
    my question, is this ok when i give contrat_cursor%ROWTYPE as parameter to the function
    and in the second context, when i get back i row from table contrat , how can i give this row as paramer , in contrat_cursor%ROWTYPE form
    i wish it was clear
    Regards
    Elyes

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

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

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

  • Forms Data-Block based on stored procedures - REF CURSOR feature NOT FUNCTIONING

    This topic is related to another topic in this forum titled "FORMS HOW TO SET QUERY SOURCE ARGUMENTS??" I posted my message there as well. I am posting as a NEW TOPIC so that it catches the attention of Oracle Support.
    I built a data form based on a stored procedure and REF CURSOR IN OUT parameter.
    My procedure takes a IN parameter to fill in the criteria for the OPEN <cursor_variable> select ... where ... statement.
    In the Value setting of the Query source Arguments , I set the VALUE to ":BLOCK_NAME.ITEM_NAME" at design time to supply the input value to the procedure. this works to the extent of making available the form item value to the stored procedure parameter. I verified this by doing an insert into some debug table , of the incoming parameter value inside my stored procedure.
    The cursor gets opened properly into the REF cursor variable. I verified this by fetching a record into a local variable and inserting the value into a debug table again in the stored procedure.
    (I took care to close and re-open the REF cursor variable again - so that the front-end can continue to fetch it from the first record. )
    ***** PROBLEM **************
    But the front end forms runtime is giving me a FRM-40301 - query returned no records even though the REF cursor is returned properly opened.
    Did anybody else face the same problem ??
    Please post what you found.
    Thanks,
    Shankaran
    null

    This topic is discussed at length in another thread "How Set Value For Query DataSource Arguments?"
    But I am posting the findings here as well.
    THIS TOPIC IS CLOSED.
    My Bad. The problem Cause : I did not include all columns in the
    cursor rowtype in the Data-block. In the wizard for the data block , I selected ONLY the columns that I needed. But I was doing a Select * from <my_table> in my open cursor <Cursor-Variable> .... The <Cursor Variable>
    itself was declared <my_table>%rowtype
    FIX : The Data Block structure (columns included as items) should match the cursor record Structure. One may or may not
    display all the columns in the LAYOUT though.
    But I don't understand why it gives such a misleading message like FRM-40301 Query retrieved no records. Oracle Team fix it.
    Hope this helps people who face the same problem.
    Thanks,

  • How to fetch NO DATA FOUND exception in Ref Cursor.

    In my procedure ref cursor is out parameter with returns dataset. in my proceudre
    its like...
    OPEN pPymtCur FOR
    select.....
    when I call this procedure from report to get dataset it causes NO DATA FOUND exception.
    How to fetch this exception in my oracle procedure so I can get some other data.
    Any Idea to do this?
    Edited by: Meghna on 17-Jun-2009 22:28

    Mass25 wrote:
    Correct me if I am wrong.
    So if I do something as follows in my stored proc, I do not have to check for NO_DATA_FOUND?
    OPEN my_CuRSR FOR
          SELECT DISTINCT blah blah blahmy_cursr is what I am returning as OUT param in my SP.Correct. At the point you open the cursor, oracle has not attempted any 'fetch' against the data so it won't know if there is any data or no data. that only occurs when a fetch is attempted.
    Take a read of this:
    [PL/SQL 101 : Understanding Ref Cursors|http://forums.oracle.com/forums/thread.jspa?threadID=886365&tstart=0]

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

  • Select cast in ref cursor

    I use ref cursor in function parameter "OUT"
    On prodecedure call this function and execute loop on cursor. Is possible?
    This error ora-22905
    This example.
    FUNCTION f1(p_cursor OUT curtyp
    p_value IN number) return varchar2 is
    begin
    open p_cusor for select c1, c2, (c1+c2) c3, (c1/2) from table t1, table2 t2 where c5=p_value;
    return 'SUCESS!';
    exception
    when no_data_found then
    return 'ERROR!'.
    end;
    procedure test(p_value in number) is
    v_cursor curtyp;
    begin
    vmsg := f1(v_cursor,p_value);
    for cs in (select * from table(v_cursor)) loop
    end loop;
    end;
    Thanks!

    I do not use fetch to not declare variables and minimize lines. If it were to declare a table type record, which would change the type every time you add a new field in the sql. Ja cursor type in the problem does not exist. but decided that using the fetch and through the cusor without the use of "is".
    Solution:
    v_menserro:= sisarr.pk_parcelamento2009.debitos_da_pessoa(v_resultado
    ,p_seq_debito
    ,null
    ,null
    ,null
    ,null);
    if nvl(v_menserro,'nulo')<> 'nulo' then
    return v_menserro;
    end if;
    loop
    FETCH v_resultado INTO v_situacao, v_tip_pessoa, v_cod_uf, v_nom_municipio, v_sig_uf,
    v_num_cpf_cnpj, v_num_cpf_cnpj_formatado , v_seq_debito, v_sig_unidade_ibama, v_des_debito,
    v_sig_tipo_debito, v_cod_tipo_debito, v_dat_vencimento, v_sig_moeda_br, v_val_original,
    v_val_saldo_real, v_num_processo;
    if v_situacao = 'REPARCELAR' then
    return 'Já existe um parcelamento prévio para o débito.';
    end if;
    end loop;
    Even if it is a bad practice, need to read several cursor in the function above
    Thanks
    Julio
    Edited by: JulioN64 on 06/07/2009 12:44

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

Maybe you are looking for

  • Exceptions in Substep:Rules Error

    Hi Friends, I am new to this portal and I seek you guys help to resolve the below error its very urgent. I have encountered an error while updating the data from PSA to Infocube i.e. Purchasing Data Cube 0PUR_C01 from the Data Source 2LIS_02_ITM in R

  • Is there any trick to make  Web.Show_Document less "smart"?

    It seems that when you use it to open a url that doesn't begin with "http://", "file://" etc. (e.g. "www.cnn.com"), it appends the url parameter to the current application server url before sending it to the browser. Well thanks a lot, but I don't wa

  • Error while extracting

    Hi, I keep getting the same error while extracting from various BC data sources. The error is about some Time Stamp. It says the time stamp in source is not the same as that in BW. I have replicated and activated again and again but keep getting that

  • Multiple Company data on 1 HTMLDB database

    Hi, I would like to find out the options for having multiple company data stored in a database with 1 HTMLDB schema. I have used VPD before and this is an option but I would like to know what HTMLDB can handle without requiring application changes. N

  • HT1222 WHY IS MY IPOD TAKING 6 HOURS TO UPDATE?  WON'T LET ME LOAD SONGS TILL I UPDATE TO LATEST VERSION, BUT I DON'T HAVE 8 HOURS TO WAIT FOR UPDATE

    IPOD HASN'T BEEN UPDATED IN A WHILE.  EVERYTIME I HOOK TO COMPUTER, IT WANTS TO UPDATE BUT IT TAKES LIKE 6 HOURS.  I CAN'T WAIT THAT LONG, BUT IT WON'T LET MY ADD ANY SONGS TO MY IPOD TILL I UPDATE.  WHAT COULD BE WRONG?