Passing array args into stored procs

Hi,
we are trying to use TopLink to perform the mapping of a pretty large schema (200+ tables). For the purpose UI presentation we only need a few different view types, not the full information in the schema, so we want to provide specific "view objects" mapped to the DB that can be batch read by their ids.
Defining views in the DB and mapping these to objects with TopLink doesn't work well because the views require joins and the tables are pretty large (the WHERE IN on the ids of the rows to read from the view is only applied after the entire view is instantiated).
Alternatively, we are trying to use stored procedures that take a VARRAY or TABLE OF INTEGER as input arg and return respective cursors. However, we couldn't figure out how to pass array infos into a stored proc using TopLink. Any suggestions?
Thx,
Olaf

I believe when you're doing it with an insert, you're saying "execute this insert statement a bunch of times, here's all the values in advance", which is different than passing an array to a stored procedure where you want it to execute once.
Oracle's ODBC driver doesnt support Associative Arrays (aka index-by tables).
Hope it helps,
Greg

Similar Messages

  • Passing arrays to Oracle Stored procedure.

    Have any body passed arrays to Oracle stored procedures while the app is running in Weblogic app server. I am able to pass the arrays with regular JDBC connection. If I run the same piece of code using a connection recieved from the datasource of weblogic server, its not working. I am getting serialization errors with the ArrayDescriptor class. Looks like the ArrayDescriptor is not serializable.
    Does anybody know solution/workaround to pass arrays ?
    Thanks in advance

    you could write a wrapper class that extends ArrayDescriptor and implements serializable...
    for example your class would look something like this.
    public class MyArrayDescriptor extends ArrayDescriptor
    implements Serializable
    in your regular code use the wrapper class in place of the ArrayDescriptor (it will contain all the same methods as the real ArrayDescriptor) and you should be able to toss your wrapper class anywhere you please.

  • Passing array to oracle stored procedure in VC++ 2005

    Hi,
    I am try to send an array of integers to a stored procedure via ODBC 10.2.0.3 on VC++2005 enviornment. I get the below error
    ORA-06550: line 1, column 7:
    PLS-00306: wrong number or types of arguments in call to 'MYPROC1'
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored ... Error Code = 6550
    []E R R O R
    The same code works if I use an INSERT statement.
    SQLUSMALLINT* rowsProcessed = new SQLUSMALLINT;
    RETCODE nRetCode;
    const int arraySize = 200;
    long ptrVal[arraySize];
    long ptrInd[arraySize];
    long ptrStatus[arraySize];
    for (int i = 0; i < arraySize; i++)
    ptrVal = i;
    ptrInd = 0;
    nRetCode = SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAM_BIND_TYPE, SQL_PARAM_BIND_BY_COLUMN, 0);
    // assign the number of sets of parameters that are to be inserted
    nRetCode = SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAMSET_SIZE, (SQLPOINTER)iSizeOfArray, 0);
    // assign an array to retrieve status info for each row of parameter values
    nRetCode =SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAM_STATUS_PTR, (SQLPOINTER)ptrStatus, 0);
    // assign a buffer to store the number of sets of parameters that have been processed
    nRetCode = SQLSetStmtAttr(m_hstmt, SQL_ATTR_PARAMS_PROCESSED_PTR, (SQLPOINTER)rowsProcessed, 0);
    nRetCode = SQLBindParameter(m_hstmt, nParamIndex, nDirection, SQL_C_LONG, SQL_INTEGER, 0, 0, ptrVal, 0, ptrInd);
    //suceeds
    SQLPrepare(m_hstmt, (SQLCHAR*)"INSERT INTO my_table VALUES (?)", SQL_NTS);
    //fails
    SQLPrepare(m_hstmt, (SQLCHAR*)"{CALL mypackage.myproc1(?)}", SQL_NTS);
    SQLExecute(m_hstmt);
    package is
    create or replace package mypackage
    as
    type mytable is table of binary_integer;
    procedure myproc1( l_tab in mytable);
    end;
    show errors
    create or replace package body mypackage
    as
    procedure myproc1( l_tab in mytable)
    as
    begin
    insert into my_table values (100);
    commit;
    FORALL i IN l_tab.first .. l_tab.last
    INSERT into my_table values( l_tab(i) );
    end;
    end;
    any ideas?

    I believe when you're doing it with an insert, you're saying "execute this insert statement a bunch of times, here's all the values in advance", which is different than passing an array to a stored procedure where you want it to execute once.
    Oracle's ODBC driver doesnt support Associative Arrays (aka index-by tables).
    Hope it helps,
    Greg

  • Unable to pass the values to stored proc using presentation variable in OBI

    Hi All,
    Need your help regarding in resolving an issue in OBIEE 10.1.3.4.1
    There is an OBIEE requirement whereby two prompts need to be defined.
    1.     Textbox prompt
    2.     Drop-down prompt
    The dropdown values should be populated using textbox prompt. So, we have used presentation variable in textbox prompt and passing the same to select query of drop-down.
    Until this step, the report works just fine.
    Now, the value in both textbox and drop-down needs to be passed to stored proc.
    While trying to pass the values by using the presentation variable, the following error comes-up saying
    Session variable has no value definition.
    Note:Although the corresponding session variable has been set to default value,still the error appears.
    Please advise.
    Regards,
    Prasad

    "Session variable has no value definition" I'm assuming typo error and it should be presentation variable.
    Set default value for presentation variable that may work

  • Pass array to oracle stored procedure

    I have such a problem: I have to pass array to stored procedure, so I declare type:
    create type tNumberArray as table of number
    and create procedure:
    create or replace procedure proc_1 (in_param in tNumberArray) as
    .... BODY OF PROCEDURE ...
    when I call this procedure from C# like this:
    int []pParam = new int[3] {1,2,3};
    OracleCommand cmd = new OracleCommand("proc_1", dbConn);
    cmd.CommandType = CommandType.StoredProcedure;
    OracleParameter param14 = new OracleParameter("param", OracleDbType.Decimal);
    param14.Value = pParam;
    param14.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
    param14.Size = 3;
    param14.Direction = ParameterDirection.Input;
    cmd.Parameters.Add(param14);
    cmd.ExecuteNonQuery();
    an error occures. It say that there invalid number or type of parameters.
    But when I declare both type and procedure in a package everything goes fine.
    What is the matter? Did anybody have the same problem?

    Not I got next problem:
    when I cannot pass parameter to stored procedure and get array fro it. In other words returning array from procedure and passing some input parameters to it does not word!
    Does anybody know why it happens?

  • Passing array variables into functions (and why I'm hopeless at arrays)

    OK, I have spent a day on this now and have done some fairly
    extensive searching online. The problem is - I am hopeless with
    arrays (and probably just actionscript generally for that matter)
    I want to create an array of buttons, so I set up an array of
    actions, step through each item and then try to pass that array
    action into an onclick button for an attached button
    The problem I have is that the onclick function ALWAYS
    returns the last item in the array.
    Help!
    Code below:
    ----------------------------------------------------------------

    the reason for this, is that once the for loop executes, the
    'last' value is the only one remaining. what one needs to do here
    is 'store' the string in a newly created property on each button,
    like this:

  • Passing array from java stored procedure to plsql

    I have a java store procedure that is parsing an xml document and returning element values to my plsql application(8.1.7). I'm mapping a java.lang.String return type to VARCHAR2. However I'm running into the 4k limit when trying to return a string from java that is over 4k. Truncation of varchar returning over 4k is a known issue in 8i.
    So my next idea was to split that value of the element into 2000char and put in an array then pass that back to the plsql procedure. I know that oracle.sql.ARRAY can be converted into a plsql TABLE. But I believe you can only use the oracle.sql.ARRAY type when you are doing jdbc programming and are working with a connection.
    SO FINALLY MY QUESTION IS...
    Can anyone think of a solution that will allow me to pass over 4k of character data from my java stored procedure (not jdbc), back to my plsql app?
    Thanks.

    My understanding is that oracle 8 has a 4k limitation on any plsql function return data. A varchar can hold 32k within a function/package, but it cannot return more than 4k outside it's scope.
    Do you have an example you could share where you use the clob as a return type?
    Thanks!

  • Passing array data into datagrid

    Hi,
    I need to pass data from an Array ( of Strings) into a datagrid. I have used the following text:
    <mx:DataGrid id="dg1" x="400" y="50" dataProvider="{myArray}">
    <mx:columns>
              <mx:DataGridColumn headerText="Names" />
    </mx:columns>
    </mx:DataGrid>
    The DataGrid does not show any data as I have not mentioned the dataField. Can you please tell - what woud the dataField be in this case as the array contains simple strings.

    Because your adding an Object to the arrayCollection you can add as many field names as you like as below.
    <?xml version="1.0" encoding="utf-8"?>
    <mx:Application xmlns:mx="http://www.adobe.com/2006/mxml" layout="absolute" creationComplete="init()">
        <mx:Script>
            <![CDATA[
                import mx.collections.ArrayCollection;
                [Bindable]
                private var ac:ArrayCollection = new ArrayCollection();
                private function init():void {
                    var obj:Object = new Object();
                    obj.name = 'Andrew';
                    obj.town = 'Taunton';
                    obj.sex = 'Male';
                    var obj1:Object = new Object();
                    obj1.name = 'Jane';
                    obj1.town = 'Glastongury';
                    obj1.sex = 'Female';
                    ac.addItem(obj);
                    ac.addItem(obj1);       
            ]]>
        </mx:Script>
        <mx:DataGrid x="42" y="47" dataProvider="{ac}">
            <mx:columns>
                <mx:DataGridColumn headerText="Name" dataField="name"/>
                <mx:DataGridColumn headerText="Town" dataField="town"/>
                <mx:DataGridColumn headerText="Sex" dataField="sex"/>
            </mx:columns>
        </mx:DataGrid>
    </mx:Application>
    In yours you just need to loop through your data source and create the objects and add them to the collection.
    Andrew

  • Passing array to Oracle stored procedure

    Is it possible to pass an array (TYPES.Array) to an oracle stored procedure in WLI? I know it can be done in vanilla jdbc.
    I have tried to do this but I'm getting this exception:
    java.sql.SQLException: Fail to convert to internal representation:

    Well well well......I was able to fix the same.
    The implementation for writeSQL is the catch. We need to give the conversion only in that.
    Anyway, thanks.

  • Passing ARRAY object to stored procedure problem

    I've created a stored procedure that accepts as a parameter a
    database type
    that I have defined as a VARRAY. (create type XXX)
    When I attempt to pass an ARRAY object to this stored procedure
    through JDBC
    (Thin-client driver) I recieve the Oracle internal error ORA-
    00600 and the
    first "parameter" is [12760].
    Has anyone else attempted the same sort of thing w/ success?
    I am including the Java source code to help the investigation
    private void chad(int[] railcarIds) throws NonFatalDBException,
    FatalDBException {
    CallableStatement theStatement = null;
    try {
    theStatement = this.getDatabaseConnection().prepareCall("{call
    RomsRepairPackage.chad(?)} ");
    // create an ARRAY object to send to the procedure
    ArrayDescriptor ad =
    ArrayDescriptor.createDescriptor("RAILCARIDVARRAYTYPE",
    this.getDatabaseConnection());
    ARRAY theArray = new ARRAY(ad, this.getDatabaseConnection(),
    railcarIds);
    // set the input parameter which is the array of railcar ids
    ((OracleCallableStatement)theStatement).setARRAY(1, theArray);
    theStatement.execute();
    theStatement.close();
    } catch (SQLException sqle) {
    System.out.println("ouch");
    Thank you for any help,
    Chad Sheley
    Senior Consultant
    Cap Gemini
    Des Moines, IA
    null

    Hi
    Can u plzz help me as to how did u write the procedure to take arrays as input.I also have to write aprocedure that takes arrays and returns arrays.Plzz can u give me a working sample as I have not found any help anywhere
    <BLOCKQUOTE><font size="1" face="Verdana, Arial">quote:</font><HR>Originally posted by Chad Sheley ([email protected]):
    I've created a stored procedure that accepts as a parameter a
    database type
    that I have defined as a VARRAY. (create type XXX)
    When I attempt to pass an ARRAY object to this stored procedure
    through JDBC
    (Thin-client driver) I recieve the Oracle internal error ORA-
    00600 and the
    first "parameter" is [12760].
    Has anyone else attempted the same sort of thing w/ success?
    I am including the Java source code to help the investigation
    private void chad(int[] railcarIds) throws NonFatalDBException,
    FatalDBException {
    CallableStatement theStatement = null;
    try {
    theStatement = this.getDatabaseConnection().prepareCall("{call
    RomsRepairPackage.chad(?)} ");
    // create an ARRAY object to send to the procedure
    ArrayDescriptor ad =
    ArrayDescriptor.createDescriptor("RAILCARIDVARRAYTYPE",
    this.getDatabaseConnection());
    ARRAY theArray = new ARRAY(ad, this.getDatabaseConnection(),
    railcarIds);
    // set the input parameter which is the array of railcar ids
    ((OracleCallableStatement)theStatement).setARRAY(1, theArray);
    theStatement.execute();
    theStatement.close();
    } catch (SQLException sqle) {
    System.out.println("ouch");
    Thank you for any help,
    Chad Sheley
    Senior Consultant
    Cap Gemini
    Des Moines, IA<HR></BLOCKQUOTE>
    null

  • Passing array parameters to Stored procedure

    Hi,
    I need to call a procedure repeatedly with different set of parameters. Instead To do this, I can form a parameter arrays and pass it to the procedure. This is working fine with Oracle 8.1.7 database and Oracle 8.1.7 odbc driver.
    Is there any difference in the way 8.1.6 Oracle ODBC driver behave? When we use the same code with 8.1.6 ODBC driver (with either 8.1.6 database or 8.1.7 database), and pass an array of n elements to the stored procedure, first elemet in the array is processed correctly and for the remaining n-1 times the same value is getting used (which leades to a unique constraint violation since procedure in this case does an insert). Soem of our clients are on 8.1.6 and so we need to get this working on it too.
    Also are you aware if Microsoft ODBC driver implements this correctly. When we traced with ODBC trace, it was executing the procedure n times one after the other thereby simulating the effect but poor performance. (MDAC 2.6).
    Is there any extra settings to be done?
    Thanks
    Sree

    Hi Justin,
    When I installed 8.1.6.6 ODBC driver this problem went off, but I recieved another problem.
    I am getting
    "ORA-01460 unimplemented or unreasonable conversion requested"
    on execution of some procedures with parameter arrays. They work fine with 8.1.7.0.
    Any idea? Is it suggested that I use 8.1.7 ODBC driver with 8.1.6 server/client? Will it create some other problem?
    Thanks
    Sree

  • How to pass the values to stored proc using presentation variable in OBIEE

    Need your help regarding in resolving an issue in OBIEE 10.1.3.4.1
    There are 6 reports say ‘A’,’B’,’C’,’D’,’E’,’F’ in the same subject area.
    The reports are being configured with prompts using either the repository/presentation variables.
    One of the reports say ‘A’ has been configured to pass the values using presentation variables from the prompt in Advanced Tab of the report request to the stored procedure defined in the Execute Before Query section of the connection pool.
    After running another report ‘B’ in the same subject area, upon visiting the report ‘A’ view display error is being seen ( Please have a look below screen shot for your reference) .
    Speculate the issue is around presentation variables of report ‘A’ getting initialized even before running the report.
    Appreciate your earliest advise as this is a prod issue.

    Hi Prasad,
    I got your note, you should not use Session variable syntax to call presentation variable.
    you should use like @{AIC_PROJ_PLAT_SEQ_NO}
    One more thing: first test the variable AIC_PROJ_PLAT_SEQ_NO value then try to pass to SP.
    Hope this helps

  • Pass array to a stored procedure

    I have a comma delimited string that looks like this:
    1,t,2,t,3,f,4,t
    So I want to parse threw ththis string I send and update the DB. The numbers are ID's and t and f is the other field. An example would be great

    Actually, Tom, what you missed was the important bit. The poster wants to parse a comma separated string. .
    v := myTableType( myType( 1,'t' ), myType( 2,'f' ) );Your solution skips the hard bit ;)
    Here's my go. Of course, it requires the inputter to ensure that the string is correctly parsable (i.e. an even number of values, alternate values numeric).
    Cheers, APC
    SQL> CREATE OR REPLACE TYPE o AS OBJECT  (col1 NUMBER, col2 VARCHAR2(1));
      2  /
    Type created.
    SQL> CREATE OR REPLACE TYPE ot AS TABLE OF o;
      2  /
    Type created.
    SQL> DECLARE
      2     lv VARCHAR2(32767);
      3     i NUMBER;
      4     j NUMBER;
      5     tt ot;
      6     x number;
      7     y varchar2(1);
      8  BEGIN
      9     -- initialise
    10     lv := '1,t,2,t,3,f,4,t';
    11     tt := ot();
    12     i := 0;
    13     j := 0;
    14     LOOP
    15        i := i+1;
    16        EXIT WHEN instr(lv, ',', 1, i) = 0;
    17        --  get first value
    18        j := j+1;
    19        x := to_number(trim(substr(lv, instr(lv, ',', 1, i)-1, 1)));
    20        --  get second value
    21        i := i+1;
    22        y := trim(substr(lv, instr(lv, ',', 1, i)-1, 1));
    23        -- add found values to array
    24        tt.extend;
    25        tt(j) := o(x, y);
    26     END LOOP;
    27     dbms_output.put_line('recs='||to_char(tt.count));
    28  END;
    29  /
    recs=4
    PL/SQL procedure successfully completed.
    SQL>

  • Help: Trying to pass a parameter to stored proc from FORMS

    I am working on a FORMS based on stored procedure with 7 parameters. All parameters work except p_sort for ORDER BY CLAUSE.
    Any suggestions?
    Thank you in advance.
    Jimmy

    pls post some more details .

  • Arrays as IN/OUT parameters to stored procs

    I need the ability to pass Java arrays as input parameters and receive arrays as output parameters from stored procedures. I searched this forum for "array stored procedure" and came up with 9 posts dating back to April 30, 1999. In every one of these posts, people have asked how this can be done, and as yet there has not been any real solution provided. One messy solution is to add another stored proc that takes the array items as scalars and builds a PL/SQL table to pass to the original stored proc.
    I am getting the impression that using arrays for IN/OUT parameters to/from stored procedures is not possible with JDK 1.1. Can it be done with JDK 1.2?
    Isn't there anyone from Oracle that can provide an answer or solution?

    I've searched for a way of passing a rowtype to a stored
    procedure or passing an array to a stored procedure.
    The following example may have some pertinence. It was posted at
    http://www.classicity.com/oracle/htdocs/forums/ClsyForumID124/6.h
    tml#
    I also think that it would be useful to know how best to pas a
    ResultSet or equivalent to a Stored Procedure, if someone has
    more information. The idea is to have symmetry between the way
    data is retrieved from SP's (CURSORS) and supplied to SP's (???
    ARRAY/CURSOR) ?
    "[Example]Example of using JDBC with VARRAYS and REF CURSORs"
    This example shows how to use JDBC with VARRAYS and REF
    CURSORs.
    It also shows use of the PreparedStatement and CallableStatement
    methods.
    The example does the follows:
    1. selects from a table of VARRAYs
    2. inserts into a table of VARRAYs
    3. selects from a table of VARRAYs
    4. calls stored procedure -- parameters <ref cursor, varray>
    In order to test it, you will need to do two things first:
    1) Create related tables and types first. The screipt is given
    below.
    2) Create a package that gets called from JAVA code. The script
    is given below.
    ======================= Step 1 create tables etc. cute here
    ==================
    -- Run this through SQL*PLUS
    drop TABLE varray_table;
    drop TYPE num_varray;
    drop TABLE sec;
    -- create the type
    create TYPE num_varray as VARRAY(10) OF NUMBER(12, 2);
    -- create the table
    create TABLE varray_table (col1 num_varray);
    -- create the sec table
    create table sec (sec_id number(8) not null, sec_grp_id number
    (8) not null,
    company_id number(8) not null);
    insert into sec values (1,200,11);
    insert into sec values (2,1100,22);
    insert into sec values (3,1300,33);
    insert into sec values (4,1800,44);
    ==================== End of step
    1===========================================
    ================== Step 2 create package
    ====================================
    -- Run it through sql*plus
    CREATE OR REPLACE PACKAGE packageA AS
    type sctype is ref cursor return SEC%ROWTYPE;
    procedure get_port_consensus(sc IN OUT sctype, arr IN
    num_varray);
    procedure test_port_consensus(sc IN OUT sctype);
    END packageA;
    CREATE OR REPLACE PACKAGE BODY packageA AS
    procedure test_port_consensus(sc IN OUT sctype)
    IS
    testArr num_varray := num_varray(200, 1100, 1300, 1800);
    BEGIN
    get_port_consensus(sc, testArr);
    END test_port_consensus;
    procedure get_port_consensus(sc IN OUT sctype, arr IN num_varray)
    IS
    BEGIN
    open sc for select * from sec
    where sec_grp_id = arr(1)
    or sec_grp_id = arr(2)
    or sec_grp_id = arr(3)
    or sec_grp_id = arr(4);
    END get_port_consensus;
    END packageA;
    ===================== End of step 2
    ===================================
    ============ JAVA code to test the whole thing
    ========================
    import java.sql.*;
    import oracle.sql.*;
    import oracle.jdbc.oracore.Util;
    import oracle.jdbc.driver.*;
    import java.math.BigDecimal;
    public class ArrayExample
    public static void main (String args<>)
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver
    // Connect to the database
    // You need to put your database name after the @ sign in
    // the connection URL.
    // The example retrieves an varray of type "NUM_VARRAY",
    // materializes the object as an object of type ARRAY.
    // A new ARRAY is then inserted into the database.
    Connection conn =
    DriverManager.getConnection ("jdbc:oracle:oci8:@v81",
    "scott", "tiger");
    // It's faster when auto commit is off
    conn.setAutoCommit (false);
    // Create a Statement
    Statement stmt = conn.createStatement ();
    System.out.println("Querying varray_table");
    ResultSet rs = stmt.executeQuery("SELECT * FROM varray_table");
    showResultSet (rs);
    // now insert a new row
    // create a new ARRAY object
    int elements<> = { 200, 1100, 1300, 1800 };
    ArrayDescriptor desc = ArrayDescriptor.createDescriptor
    ("NUM_VARRAY",conn);
    ARRAY newArray = new ARRAY(desc, conn, elements);
    // prepare statement to be inserted and bind the num_varray type
    System.out.println("PreparedStatement: Inserting into
    varray_table");
    PreparedStatement ps =
    conn.prepareStatement ("insert into varray_table values (?)");
    ((OraclePreparedStatement)ps).setARRAY (1, newArray);
    ps.execute ();
    // query to view our newly inserted row
    System.out.println("Querying varray_table again");
    rs = stmt.executeQuery("SELECT * FROM varray_table");
    showResultSet (rs);
    // prepare a callable statement -- call the stored procedure
    // passing <ref cursor in out, varray in>
    System.out.println("CallableStatement: Calling Stored
    Procedure");
    OracleCallableStatement oraStmt1 =
    (OracleCallableStatement)conn.prepareCall("{ call
    packageA.get_port_consensus(?, ?) }");
    oraStmt1.registerOutParameter(1, OracleTypes.CURSOR);
    oraStmt1.setARRAY(2, newArray);
    oraStmt1.execute();
    rs = (ResultSet)oraStmt1.getObject(1);
    // loop through the result set of the ref cursor and display
    while (rs.next()) {
    System.out.println(rs.getString("sec_grp_id"));
    // Close all the resources
    rs.close();
    ps.close();
    stmt.close();
    oraStmt1.close();
    conn.close();
    public static void showResultSet (ResultSet rs)
    throws SQLException
    int line = 0;
    while (rs.next())
    line++;
    System.out.println("Row "+line+" : ");
    ARRAY array = ((OracleResultSet)rs).getARRAY (1);
    System.out.println ("Array is of type "+array.getSQLTypeName());
    System.out.println ("Array element is of type
    code "+array.getBaseType());
    System.out.println ("Array is of length "+array.length());
    // get Array elements
    BigDecimal<> values = (BigDecimal<>) array.getArray();
    for (int i=0; i<values.length; i++)
    BigDecimal value = (BigDecimal) values;
    System.out.println(">> index "+i+" = "+value.intValue());

Maybe you are looking for