PL/SQL array bind output variable

I've been trying to learn how to pass an array to an pl/sql script. Getting the data into the db seems to be working fine, but I would like to know if there was a problem inserting the data. More specifically, I would like to know THE SPECIFIC ROW that caused the problem.
pl/sql code:
create or replace procedure pp (
          v_out      out number,
          v_listtype in repair_codes.listtype%type,
v_repaircode in repair_codes.repaircode%type
is
begin
insert into repair_codes (listtype, repaircode) values (v_listtype,v_repaircode);
     v_out:=1;
commit;
     --just setting up test variable for now     
end;
vb.code:
Dim cmd As New OracleCommand("pp", dbConn)
cmd.CommandType = CommandType.StoredProcedure
cmd.ArrayBindCount = 3
Dim al(2) As String
Dim ar(2) As String
al(0) = "JOE1"
al(1) = "JOE2"
al(2) = "JOE3"
ar(0) = "TEST1"
ar(1) = "TEST2"
ar(2) = "TEST3456789"
Dim out As New OracleParameter("v_out", OracleDbType.Varchar2, 20)
out.Direction = ParameterDirection.Output
cmd.Parameters.Add(out)
Dim listtype As New OracleParameter("v_listtype", OracleDbType.Varchar2)
listtype.Value = al
cmd.Parameters.Add(listtype)
Dim repaircode As New OracleParameter("v_repaircode", OracleDbType.Varchar2)
repaircode.Value = ar
cmd.Parameters.Add(repaircode)
dbConn.Open()
Try
cmd.ExecuteNonQuery()
Catch ex As OracleException ' catches only Oracle errors
ex = ex
Select Case ex.Number
Case 1
MessageBox.Show("Error attempting to insert duplicate data.")
Case 12545
MessageBox.Show("The database is unavailable.")
Case Else
MessageBox.Show("Database error: " & ex.Message.ToString())
Dim wha = ex.Errors(0).ArrayBindIndex 'always '0'
End Select
Finally
dbConn.Close()
End Try
error:
OracleParameter.ArrayBindSize is invalid
Code above will work if I remove everything about the 'output' variable
To test I would like to put in data for a column that is too large, have all other rows inserted, but return the row that had bad data. Thanks for any thoughts on this-

I have a similar issue, i.e. the pl/sql table type as out parameter is causing probleml in one API related to Oracle Applications. I have singled this problem out by creating wrappers and testing them against BPEL process. Now as soon as I put an out parameter with pl/sql table in my wrapper, I start getting errors. Why the invoke even care about what is in output while calling the API? How can I get rid of it. I am not able to pin point where exactly you made the changes. Could you please share some more info or possibly share the BAD and GOOD code.
We will probably get away with this by creating just a wrapper that would have NO out parameter as PL/SQL table as I don't think we need it anyway.
Still want to know what is the issue here as we would like to avoid any custom wrapper creation?
Shobhit
Message was edited by:
Shobhit.Kapila

Similar Messages

  • Output Array Binding

    I am looking for an example of output array binding (equivalent to BULK COLLECT). The input sample code is very good, but the documentation talks about output binding as well, but there are no examples.
    If anyone has a short example that shows how to set up the bind variables, I would very much appreciate it.

    Hi,
    From
    http://download-west.oracle.com/docs/cd/B19306_01/win.102/b14307/featOraCommand.htm#BABBDHBB
    <snippet>
    // execute the cmd
    cmd.ExecuteNonQuery();
    //print out the parameter's values
    Console.WriteLine("parameter values after executing the PL/SQL block");
    for (int i = 0; i < 3; i++)
    Console.WriteLine("Param2[{0}] = {1} ", i,
    (cmd.Parameters[1].Value as Array).GetValue(i));
    for (int i = 0; i < 3; i++)
    Console.WriteLine("Param3[{0}] = {1} ", i,
    (cmd.Parameters[2].Value as Array).GetValue(i));
    </snippet>
    Cheers,
    Greg

  • Bind PL/SQL array to PHP array

    Hi all!
    I try to bind a PL/SQL array (nested tables, index by integer) returned by a PL/SQL-function to an PHP array.
    Here is the code:
    create or replace package MyPackage as
    TYPE my_type IS TABLE OF VARCHAR2(1024);
    FUNCTION MyFunction RETURN my_type;
    end MyPackage;
    create or replace PACKAGE BODY MyPackage is
    FUNCTION MyFunction RETURN my_type IS
    t_docs my_type;
    begin
    t_docs := my_type('val0','val1','val2');
    return t_docs;
    end MyFunction;
    end MyPackage;
    In the PHP-code ist looks like this
    $query = "begin :vals := MyPackage.MyFunction; end;";
    $stmt = oci_parse ($conn, $query);
    oci_bind_array_by_name($stmt, ":vals", $vals_array, 5, 512, SQLT_CHR);
    oci_execute ($stmt);
    Output:
    PLS-00382: expression is of wrong type. Error in Line....
    This error point to
    begin :vals := MyPackage.MyFunction; end;
    ^^^
    Questions:
    Is it generally possible to bind a pl/sql array to a php array? Or only the other was around?
    Could you please post a snipet of code how to do it the right way :-)
    Thanks a lot for your help! Christian

    As you noted, you can't return a PL/SQL array and map it to a PHP array when it is a record type. Likewise, you can't map an object type to a PHP array. You can return a reference cursor through PL/SQL, and then fetch the function result with oci_fetch_assoc($rc).
    Alternatively, you can return an object type collection or a pipelined table function result into PHP. It's a bit long but you'll find examples on my blog. Start here, and there's a link to a full discussion of pipelined table functions:
    http://blog.mclaughlinsoftware.com/2009/03/19/beats-a-reference-cursor/
    This is an object table example, which you may prefer over pipelined table functions:
    http://blog.mclaughlinsoftware.com/2009/03/23/object-record-collections/
    Hope this helps.

  • Reg: PLS-00418: array bind type must match PL/SQL table row type error

    I am trying to access a table of records through JDBC OracleCallableStatement. I am able to do it fine for all mappings except for the ones below
    TYPE CAT_CD_TYPE IS TABLE OF A.B %TYPE INDEX BY BINARY_INTEGER;
    TYPE ORG_CD_TYPE IS TABLE OF C.D %TYPE INDEX BY BINARY_INTEGER;
    Column B is CHAR(1) and Column D is CHAR(2). I am trying to register the out parameters of Oraclecallablestatement as
    cstmt.registerIndexTableOutParameter(2, 2000, OracleTypes.CHAR, 0);
    cstmt.registerIndexTableOutParameter(3, 2000, OracleTypes.CHAR, 0);
    All the other mappings work fine. These two fail with the error
    SQLException in invokeDBPackage() : ORA-06550: line 1, column 32:
    PLS-00418: array bind type must match PL/SQL table row type
    ORA-06550: line 1, column 35:
    PLS-00418: array bind type must match PL/SQL table row type
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    I tried other OracleTypes mappings too but no luck so far.
    Any advice on this would be greatly appreciated.

    Hi,
    I'm not sure it's reasonable to expect someone to sift through that much stuff.
    Which parameter is it having a problem with?
    Can you modify the following to reproduce the behavior?
    Thanks
    Greg
    create package mypack5 as
    TYPE v2array is table of emp.ename%type index by BINARY_INTEGER;
    PROCEDURE test_it(thearray IN v2array, numrecs out number);
    END;
    CREATE or replace PACKAGE BODY MYPACK5 AS
    PROCEDURE test_it(thearray IN v2array, numrecs out number)
    IS
    begin
    numrecs := thearray.count;
    END;
    END;
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    public class indexby
    public static void Main()
    OracleConnection con = new OracleConnection("data source=orcl;user id=scott;password=tiger;");
    con.Open();
    OracleCommand cmd = new OracleCommand("mypack5.test_it", con);
    cmd.CommandType = CommandType.StoredProcedure;
    OracleParameter Param1 = cmd.Parameters.Add("param1", OracleDbType.Varchar2);
    Param1.Direction = ParameterDirection.Input;
    Param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
    Param1.Size = 3;
    string[] vals = { "foo", "bar", "baz" };
    Param1.Value = vals;
    OracleParameter Param2 = cmd.Parameters.Add("param2", OracleDbType.Int32, DBNull.Value, ParameterDirection.Output);
    cmd.ExecuteNonQuery();
    Console.WriteLine("{0} records passed in", Param2.Value);
    con.Close();
    }

  • PLS-00418: array bind type must match PL/SQL table row type

    If a PL/SQL table is indexed by CHAR and is a parameter
    in a Stored Program, we are not able to call the stored
    program from the Java code.
    We get the following error code.
    java.sql.SQLException: ORA-06550: line 1, column 62:
    PLS-00418: array bind type must match PL/SQL table row type
    ORA-06550: line 1, column 7:
    PL/SQL: Statement ignored
    But if we change the CHAR into VARCHAR2 then it works.
    We are using Oracle9i Enterprise Edition Release 9.2.0.5.0 -64bit Production ,
    JServer Release 9.2.0.5.0 - Production
    and JDK1.4.
    Thanks
    Push..

    Hi,
    I'm not sure it's reasonable to expect someone to sift through that much stuff.
    Which parameter is it having a problem with?
    Can you modify the following to reproduce the behavior?
    Thanks
    Greg
    create package mypack5 as
    TYPE v2array is table of emp.ename%type index by BINARY_INTEGER;
    PROCEDURE test_it(thearray IN v2array, numrecs out number);
    END;
    CREATE or replace PACKAGE BODY MYPACK5 AS
    PROCEDURE test_it(thearray IN v2array, numrecs out number)
    IS
    begin
    numrecs := thearray.count;
    END;
    END;
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    public class indexby
    public static void Main()
    OracleConnection con = new OracleConnection("data source=orcl;user id=scott;password=tiger;");
    con.Open();
    OracleCommand cmd = new OracleCommand("mypack5.test_it", con);
    cmd.CommandType = CommandType.StoredProcedure;
    OracleParameter Param1 = cmd.Parameters.Add("param1", OracleDbType.Varchar2);
    Param1.Direction = ParameterDirection.Input;
    Param1.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
    Param1.Size = 3;
    string[] vals = { "foo", "bar", "baz" };
    Param1.Value = vals;
    OracleParameter Param2 = cmd.Parameters.Add("param2", OracleDbType.Int32, DBNull.Value, ParameterDirection.Output);
    cmd.ExecuteNonQuery();
    Console.WriteLine("{0} records passed in", Param2.Value);
    con.Close();
    }

  • Defining xsd and assiging an array to the output variable in a BPELprocess

    I have created a BPEL application in which a web service has been invoked which returns an array.If the array has a fixed size i am able to define the XSD,but what if the array does not have a fixed size.How should i define the xsd in this case,i mean how should the output node be defined.Also how can i assign the array returned by the webservice to the Output variable using the assign activity.

    Hi,
    What you could do is set the second step to loop.
    Then use as one of the parameters to VI YY the string array using RunState.LoopIndex as the array index.
    eg. Locals.MyStringArray[RunState.LoopIndex]
    Hope this helps
    Regards
    Ray Farmer
    Regards
    Ray Farmer

  • How to bind local variables in complex query in PL/SQL

    Hi
    I have long complex query with local varibales; when I run in Dynamic SQL I get an error. Not sure which is the easiest way to bind local variables.
    L_QUERY := q'[select m.segment1 col1,
          '1' col2,
          '13' col3,
          l.operand col4,
          0 col5,
           'Y' col8,
          'N' col9,
          'N' col10,
       decode(h.name,'09_UKOR_*','EOS Credit','10_UKOR_*','TopUp','11_UKOR_*','Main') col18
    from qp_list_headers_v h,
          qp_list_lines_v l,
          mtl_system_items m
    where h.name in ('09_UKOR_*','10_UKOR_*','11_UKOR_*')
    and h.list_header_id = l.list_header_id
    and m.inventory_item_id = l.product_attr_value
    and m.organization_id  = 84
    UNION all
    SELECT qs.PRODUCT_ATTR_VALUE col1,
           hca.account_number col2,
           decode (su.site_use_code,'BILL_TO','21','SHIP_TO','18') col3,
           0 col4,
           qs.operand col5,
           null col6,
           null col7,
           'N' col8,
           'Y' col9,
           'N' col10,     
    --Local variables
          (case when (trunc(nvl(qq.start_date_active,sysdate)) between l_cur_year_from  and l_cur_year_to) and  
                      ( trunc(nvl(qq.end_date_active,l_cur_year_to)) >= trunc(l_cur_year_to) )  then    'TopUp'
                when (trunc(qq.start_date_active) between l_next_year_from  and l_next_year_to) and  
                      ( trunc(nvl(qq.end_date_active,l_next_year_to)) >= l_next_year_to)  then   'Main'              
                when (trunc(qq.start_date_active) between l_last_year_from  and l_last_year_to) and  
                      ( trunc(nvl(qq.end_date_active,l_last_year_to)) >= l_last_year_to )  then  'EOS Return'
           end )col18,
    --Local variables
           (case   when (trunc(qq.start_date_active) between l_next_year_from  and l_next_year_to) and  
                      ( trunc(nvl(qq.end_date_active,l_next_year_to)) >= l_cur_year_to )  then   'N'
              else
                    'Y'  end ) col21
       FROM qp.qp_list_headers_b qlhb,
            qp.qp_list_headers_tl qlht,
            qp.qp_qualifiers qq,
            qp_modifier_summary_v qs,
            hz_cust_site_uses_all su,
            hz_cust_acct_sites_all  sa,
            hz_cust_accounts hca
    WHERE 1=1
          and qlhb.LIST_TYPE_CODE       = 'DLT'
          and nvl(qlhb.active_flag,'Y') = 'Y'
          and qlhb.list_header_id       = qlht.list_header_id
          AND qq.list_header_id         = qlhb.list_header_id
          and qq.list_type_code         = qlhb.LIST_TYPE_CODE
          and qq.QUALIFIER_CONTEXT      = 'CUSTOMER'
          and qs.list_header_id         = qlhb.list_header_id
          and qs.LIST_LINE_TYPE_CODE    = 'DIS'
          and su.site_use_id            = qq.qualifier_attr_value --1064
          AND  su.cust_acct_site_id     = sa.cust_acct_site_id
          AND  sa.cust_account_id       = hca.cust_account_id ]';
    --call Dynamic SQL function
    l_cursor := DBMS_SQL.OPEN_CURSOR;
    DBMS_SQL.PARSE(l_cursor, p_QUERY , DBMS_SQL.NATIVE);
    l_rows := DBMS_SQL.EXECUTE(l_cursor);
    Any help will be much appreciated.
    iI guess I should use DBMS_SQL.BIND_VARIABLE to bind all variables seperately so not to mess with query

    1) What is the error you get?
    2) If you use bind variables inside a query, you should prefix them with colons, so use :l_cur_year_from etc.
    3) Why are you using dbms_sql instead of native dynamic sql and/or ref-cursors?
    Toon

  • Support for Array Binding and PL/SQL tables (IN, INOUT, or OUT)

    I have attempted, unsuccessfully, to use array binding in stored procedure/function calls where the sp/sf has parameters that are PL/SQL tables. I have seen the topic floating around in this forum, but I have not seen the explicit questions:
    - Does ODP.NET support PL/SQL tables as IN, INOUT or OUT parameters to stored procedures/functions?
    - Will any planned ODP.NET release support PL/SQL tables as IN, INOUT or OUT parameters to stored procedures/functions?
    I am aware that I can use REF CURSORS to handle the OUT situation, but I need to make a design decision concerning supporting parameters of IN and INOUT PL/SQL tables.
    Thanks.
    James

    You really MUST do this!! - i.e. include support for PL/SQL table parameters (IN INOUT and OUT) in a future release of ODP.NET.
    PL/SQL tables are a fundamental type in Oracle stored procedures and you will be preventing a huge number of existing projects from migrating to .NET if you don't acknowledge them as part and parcel of Oracle programming.
    I sincerely hope support for PL/SQL table parameters is treated as a serious issue.
    Think what a coup it would be for you over Microsoft (who don't currently support PL/SQL tables with their .NET native provider for Oracle and don't look as if they will at least in the short term)!
    Please, please, please!

  • Exception Handling for Array Binding

    Hi
    1)
    I am using a Stored Procedure.
    I am using array binding and if i am sending an array of count 10 to be inserted in a table and only 9 got inserted,i deliberatly inserted one errorneous record in array, the count returned by ExecuteNonQuery() is 10.Why ?
    How can i come to know exact number of rows inserted in table, how can i use Output variables, because the array bind count is 10 so if i add an output parameter it gives error ArrayBind count is wrong....
    2)
    Is it possible to roll back all the inserts if error occurs in any of the insert by Oracle engine.What it does is it inserts all correct records and leaves the errorneous record and doesn't even throw any exception or any message.
    Answer - This can be achieved by using OracleTransaction and don't use Exception handling in procedure otherwise there wont be any exception thrown by procedure which is necessary to detect if an error occured during insert.If you use exception handling OracleEngine will insert correct rows and leave errorneous record and return count of inserted + non inserted records which is wrong.
    Please help.
    Message was edited by:
    user556446
    Message was edited by:
    user556446

    You'll need to encapsulate your validation within it's own block as described below:
    -- this will die on the first exception
    declare
      TYPE T_BADDATA_TEST IS TABLE OF VARCHAR2(1000) INDEX BY binary_integer ;
      tbt T_BADDATA_TEST ;
      aBadTypeFound exception ;
    begin
       tbt(0) := 'a';
       tbt(1) := 'b';
       tbt(2) := 'c';
        for idx in tbt.first..tbt.last loop
          if tbt(idx) =  'b' then
              raise aBadTypeFound ;     
          else
              dbms_output.put_line(tbt(idx));     
          end if  ;
        end loop ;
    end ;--encapsulate the exception area in a begin/end block to handle the exception but continue on
    declare
      TYPE T_BADDATA_TEST IS TABLE OF VARCHAR2(1000) INDEX BY binary_integer ;
      tbt T_BADDATA_TEST ;
      aBadTypeFound exception ;
    begin
       tbt(0) := 'a';
       tbt(1) := 'b';
       tbt(2) := 'c';
        for idx in tbt.first..tbt.last loop
          BEGIN
          if tbt(idx) =  'b' then
              raise aBadTypeFound ;     
          else
              dbms_output.put_line(tbt(idx));     
          end if  ;
          EXCEPTION
            WHEN aBadTypeFound THEN
                dbms_output.put_line(tbt(idx) || ' is bad data');       
            WHEN OTHERS THEN
                dbms_output.put_line('exception');       
          END ;
        end loop ;
    end ;
    output:
    a
    b is bad data
    c
    ***/

  • Procedure Array Binding a Null Value

    Can you perform array binding in ODP.NET (to a procedure for example that inserts values) and assume that if there are null values in the array that the records inserted will have the corresponding null values in their records?

    Here's a quick sample using pl/sql associative arrays to insert null values into a table (I think this is what you mean)...
    SQL*Plus: Release 10.1.0.3.0 - Production on Fri Feb 18 09:38:55 2005
    Copyright (c) 1982, 2004, Oracle.  All rights reserved.
    SQL> connect /
    Connected.
    SQL> create table null_array_insert
      2  (
      3    first_name  varchar2(32) not null,
      4    middle_name varchar2(32) null,
      5    last_name   varchar2(32) not null
      6  );
    Table created.
    SQL> create or replace package null_array_test as
      2    -- create a type for each column
      3    type t_first_name is table of null_array_insert.first_name%type
      4      index by binary_integer;
      5
      6    type t_middle_name is table of null_array_insert.middle_name%type
      7      index by binary_integer;
      8
      9    type t_last_name is table of null_array_insert.last_name%type
    10      index by binary_integer;
    11
    12    -- the procedures that will perform our work
    13    procedure bulk_insert (p_first_name  in t_first_name,
    14                           p_middle_name in t_middle_name,
    15                           p_last_name   in t_last_name);
    16  end null_array_test;
    17  /
    Package created.
    SQL> create or replace package body null_array_test as
      2    procedure bulk_insert (p_first_name  in t_first_name,
      3                           p_middle_name in t_middle_name,
      4                           p_last_name   in t_last_name) is
      5    begin
      6      forall i in p_first_name.first..p_first_name.last
      7      insert into null_array_insert (first_name,
      8                                     middle_name,
      9                                     last_name)
    10                          values    (p_first_name(i),
    11                                     p_middle_name(i),
    12                                     p_last_name(i));
    13    end bulk_insert;
    14  end null_array_test;
    15  /
    Package body created.
    Here's the C# code:
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
    namespace Associative
      /// <summary>
      /// Summary description for Class1.
      /// </summary>
      class Class1
        /// <summary>
        /// The main entry point for the application.
        /// </summary>
        [STAThread]
        static void Main(string[] args)
          string connStr = "User Id=/";
          OracleConnection oraConn = new OracleConnection(connStr);
          oraConn.Open();
          // create the command object and set attributes
          OracleCommand cmd = new OracleCommand("null_array_test.bulk_insert", oraConn);
          cmd.CommandType = CommandType.StoredProcedure;
          // create parameter objects for each parameter
          OracleParameter p_first_name = new OracleParameter();
          OracleParameter p_middle_name = new OracleParameter();
          OracleParameter p_last_name = new OracleParameter();
          // set parameter type for each parameter
          p_first_name.OracleDbType = OracleDbType.Varchar2;
          p_middle_name.OracleDbType = OracleDbType.Varchar2;
          p_last_name.OracleDbType = OracleDbType.Varchar2;
          // set the collection type for each parameter
          p_first_name.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
          p_middle_name.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
          p_last_name.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
          // set the parameter values
          p_first_name.Value = new string[4]{"First 1", "First 2", "First 3", "First 4"};
          p_middle_name.Value = new string[4]{"Middle 1", "", "Middle 3", ""};
          p_last_name.Value = new string[4]{"Last 1", "Last 2", "Last 3", "Last 4"};
          // set the size for each array
          p_first_name.Size = 4;
          p_middle_name.Size = 4;
          p_last_name.Size = 4;
          // set array bind size for the columns since they
          // are a variable size type (varchar2)
          p_first_name.ArrayBindSize = new int[4]{32, 32, 32, 32};
          p_middle_name.ArrayBindSize = new int[4]{32, 32, 32, 32};
          p_last_name.ArrayBindSize = new int[4]{32, 32, 32, 32};
          // add the parameters to the command object
          cmd.Parameters.Add(p_first_name);
          cmd.Parameters.Add(p_middle_name);
          cmd.Parameters.Add(p_last_name);
          // execute the insert
          cmd.ExecuteNonQuery();
          p_last_name.Dispose();
          p_middle_name.Dispose();
          p_first_name.Dispose();
          cmd.Dispose();
          oraConn.Dispose();
    And after running the code:
    SQL> select * from null_array_insert;
    FIRST_NAME                       MIDDLE_NAME                      LAST_NAME
    First 1                          Middle 1                         Last 1
    First 2                                                           Last 2
    First 3                          Middle 3                         Last 3
    First 4                                                           Last 4
    4 rows selected.
    SQL> select * from null_array_insert where middle_name is null;
    FIRST_NAME                       MIDDLE_NAME                      LAST_NAME
    First 2                                                           Last 2
    First 4                                                           Last 4
    2 rows selected.
    SQL>Hope that helps,
    - Mark

  • Array Bind: nbr of updated rows?

    Hello,
    when using array binding with UPDATE statements, how to look up the number of updated rows?
    I couldn't find any parameter property such as ArrayBindAffectedRows.
    Is it possible to use array bind with SQL statements which return values, e.g.:
    UPDATE emp SET salary = salary + :increase
    WHERE mgr = :mgrNo
    RETURNING salary INTO :newSalary;
    Hm, arrays :increase and :newSalary might have different lengths.
    Thanks,
    Armin

    Ok this is genuinly tricky.
    The only way I can think of to get this is to use FORALL and BULK COLLECT. This does an array-bound insert from PL/SQL. But you need to pass Associative Arrays from ODP.NET to PL/SQL to get this started.
    Any other solution I could think of would require running some PL/SQL code for each update statement, for instance in a trigger. But avoiding the context switches from PL/SQL to SQL is a main reason to use array binding in the first place.
    Here's a complete sample program:
    I used inline PL/SQL for compactness, but you might want to save the block as a procedure.
    using System;
    using System.Data;
    using Oracle.DataAccess.Client;
    using Oracle.DataAccess.Types;
         public class Test
          static OracleConnection connect()
            string constr = "data source=oracle;user id=scott;password=tiger";
            OracleConnection con = new OracleConnection(constr);
            con.Open();
            return con;
        const string sql = @"
    declare
      type NumTable is table of Number index by binary_integer;
      l_managers NumTable := :mgr;
      l_increase NumTable := :inc;
      l_newSals NumTable;
      l_records int;
    begin
      forall idx in l_managers.first .. l_managers.last
        update emp
        SET
        sal = sal + l_increase(idx)
        WHERE mgr = l_managers(idx)
        RETURNING sal BULK COLLECT INTO l_newSals;
      :records_affected := l_newSals.count;
    end;
        [STAThread]
        static void Main(string[] args)
          try
            using (OracleConnection con = connect())
              string cr = new String(new char[] {(char)13});
              OracleCommand cmd = new OracleCommand(sql.Replace(cr,""),con);
              OracleDecimal[] increases = new OracleDecimal[] {10,20,30};
              int[] managers = new int[] { 7698,7839,7782};
             OracleParameter pMgr = cmd.Parameters.Add("manager",
                 OracleDbType.Int32,
                 ParameterDirection.Input);
              pMgr.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
              pMgr.Size = managers.Length;
              pMgr.Value = managers;
              OracleParameter pInc = cmd.Parameters.Add("increase",
                 OracleDbType.Decimal,
                 ParameterDirection.Input);
              pInc.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
              pInc.Size = increases.Length;
              pInc.Value = increases;
              OracleParameter pRecs = cmd.Parameters.Add("records",
                 OracleDbType.Int32 ,
                 ParameterDirection.Output);
              pRecs.CollectionType = OracleCollectionType.None;
              cmd.ExecuteNonQuery();
              int recs = (int)pRecs.Value;
              Console.WriteLine("{0} records affected",recs );
          catch (Exception ex)
            Console.WriteLine(ex);
    }

  • Queries not working with multiple bind position variables?

    still need help here - can anyone provide any direction?
    (note: this is a follow-up from prior topic, " How to use JDBC Positional Binding Style & ExecuteWithParams?")
    I created two simple view objects off of the same entity
    object to perform this test:
    #1 - ViewObject with one bind position variable - where clause: where id > ?
    #2 - ViewObject with two bind position variables - where clause: where id > ? and id < ?
    I created two separate .jspx pages, view1.jspx (one input field) and view2.jspx (two input fields), for each view object by dragging ExecuteWithParams operation onto the JSF page.
    The .jspx page with one input field works (returns result sets.) The view2.jspx page with two input fields does not work - the query does not return any result sets (no errors produced, it just does not return any rows) - I've tested my query outside of jdeveloper and it works fine. I also tried switching my inputs to make sure I did not have an illogical query (i.e., id >100 and id< 1).
    Is there anything different / extra I need to do to use two bind position variables?
    Everything in this simple test was identical except for using 2 input variables versus 1.
    Technology stack is: jdeveloper 10.1.3, jsf/ADF BC, mySQL 5.01
    Message was edited by:
    javaX

    Using the where clause: "where id > ? and id < ?” for the 2 input variables, I get the same result - no row results returned (though query works outside the browser.)
    Interestingly, I modified the where clause to “where between ? and ?”, and then used values of ‘1’ and ‘100’ to test. Using the BC4J tester, the query gave back a single row with id = 100 (should have brought back 100 rows because there are 100 records with id’s 1-100.) So I got it to return something, but not the right results. This makes me believe that a different query is being sent to MySQL other than what I'm expecting from what is shown in the SQL Statement of the View Object..
    Is there anyway to view what SQL statement is actually being sent to the database using the BC4J tester? Also, could this be an issue related to the mySQL connector drivers and JDeveloper? I’m using mysql-connector-java=3.1.11-bin.jar (10/10/2005)? First though, if I could see what query is actually being sent, this may help me to debug and figure out the problem.

  • User Defined Type - Array bind Query very slow

    Hi.
    I have following Problem. I try to use Oracle Instant Client 11 and ODP.NET to pass Arrays in SELECT statements as Bind Parameters. I did it, but it runs very-very slow. Example:
    - Inittial Query:
    SELECT tbl1.field1, tbl1.field2, tbl2.field1, tbl2.field2 ... FROM tbl1
    LEFT JOIN tbl2 ON tbl1.field11=tbl2.field0
    LEFT JOIN tbl3 ON tbl2.field11=tbl3.field0 AND tbll1.field5=tbl3.field1
    ...and another LEFT JOINS
    WHERE
    tbl1.field0 IN ('id01', 'id02', 'id03'...)
    this query with 100 elements in "IN" on my database takes 3 seconds.
    - Query with Array bind:
    in Oracle I did UDT: create or replace type myschema.mytype as table of varchar2(1000)
    than, as described in Oracle Example I did few classes (Factory and implementing IOracleCustomType) and use it in Query,
    instead of IN ('id01', 'id02', 'id03'...) I have tbl1.field0 IN (select column_value from table(:prmTable)), and :prmTable is bound array.
    this query takes 190 seconds!!! Why? I works, but the HDD of Oracle server works very hard, and it takes too long.
    Oracle server we habe 10g.
    PS: I tried to use only 5 elements in array - the same result, it takes also 190 seconds...
    Please help!

    I recommend you generate an explain plan for each query and post them here. Based on what you have given the following MAY be happening:
    Your first query has as static IN list when it is submitted to the server. Therefore when Oracle generates the execution plan the CBO can accurately determine it based on a KNOWN set of input parameters. However the second query has a bind variable for this list of parameters and Oracle has no way of knowing at the time the execution plan is generated what that list contains. If it does not know what the list contains it cannot generate the most optimal execution plan. Therefore I would guess that it is probably doing some sort of full table scan (although these aren't always bad, remember that!).
    Again please post the execution plans for each.
    HTH!

  • PL/SQL array passed to SQL IN

    Hi,
    I have a PL/SQL array which type is defined like this:
    create or replace type type_id_array as table of number(6, 3);
    then i create a variable and initilaize:
    var_1 type_id_array;
    var_1 := .....
    then i have a select statement.
    select * from table t where t.id in(var_1)
    That's it, i want to use the array in an SQL in. This seems not possible.
    Can you explain why? Any alternate solutions?
    Thanks

    user610868 wrote:
    That's it, i want to use the array in an SQL in. This seems not possible.
    Can you explain why? Any alternate solutions?SQL supports set commands specifically for arrays (in addition to the using the TABLE() method mentioned). For example:
    SQL> create or replace type TNumbers is table of number;
      2  /
    Type created.
    SQL>
    SQL> declare
      2          numList TNumbers;
      3          cnt     integer;
      4  begin
      5          numList := new TNumbers(1,2,3,4,5,6,7);
      6          select
      7                  count(*) into cnt
      8          from    user_objects
      9          where   TNumbers(object_id) member of numList;
    10          DBMS_OUTPUT.put_line( 'cnt='||cnt );
    11  end;
    12  /
    cnt=0
    PL/SQL procedure successfully completed.Obviously there are performance considerations when using arrays/collections in SQL. So before choosing a method, evaluate the performance.

  • How to assign a sql statement to a variable

    hey
    i am assigning a sql statement into a variable. But in sql statement where condition i am passing a variable, i am getting syntax error while processing this statement . Could please help me
    my code is like this
    sSql:='select id from SOURCES where name=' || vc_arr(i);
    Open C for sSql;
    ....

    If you use bind variables, you don't need the single quotes, and may avoid significant performance and security problems otherwise associated with dynamic SQL.
    sSql := 'select id from SOURCES where name = :some_value';
    OPEN C FOR sSql USING vc_arr(i);

Maybe you are looking for

  • How to show lyrics at the bottom of a music video in Premiere 6.0???

    Hi all, I am a very novice user of Premiere 6.0 and have a fun video my class is making to the tune of a popular song. I have laid down the tracks and video but need to have the lyrics running at the bottom of the screen. I made a rolling credit titl

  • Trouble with Creative Cloud

    I signed up for Photoshop and Lightroom for $9.99 per month today. I downloaded and installed Photoshop CC successfully. It works. However, Lightroom 5 asks for a serial number. I am completely lost as to how to fix the problem. I tried chat with Ado

  • Logical Database usage

    Hi, can someone explain me in what cases we use Logical Databses for Reporting and in what case we use other tables? thanks

  • PPDS order creation

    Hi all, I understand that we can combine make-to-stock and make-to-order strategy using forecasting horizon in SNP. That's, within forecasting horizon SNP creates orders only against sales order and dependent requirement and not against PIR. Can we d

  • Ad Hoc Query testing when upgrading to ECC 6.0

    Hi, We have a decentralized SAP HR system. Instead of developing custom ABAP reports, we have given permission to superusers to create their own reports using Ad Hoc Query. This has lead to large number of Ad Hoc Queries  (>2000). Techincally speakin