Passing empty Associative Array

I have a sProc that takes a number and then an optional plsql table of numbers.
I cannot figure out how to pass the empty array to Oracle. I set the param size to 0 and try to set the value to null but it throws an exception if it is null or system.dbnull.
I tried the suggestion of passing an array of size one but it passes 0 to my sproc. My sproc is doing an PLSQLTable.Count check to process the list so it needs to have count = 0;
Any ideas?
thx
jack
BTW - There is a similar thread here: Passing empty Associative Array

We are having the same problem, but the suggested work-around mentioned above will not work for us. In our case, our stored procedure has multiple TABLE parameters that it expects to have the same length.
For example, a stored procedure that is used to insert multiple records in to an "Addresses" table. Each parameter in the stored procedure represents a single element in the address (line1, line2, line3, city, state, zip code). Here's a rough facsimile of what we're working with:
TYPE tElement IS TABLE OF VARCHAR2(50) INDEX BY BINARY_INTEGER;
PROCEDURE insAddresses ( pLine1 tElement,
               pLine2     tElement,
               pLine3     tElement,
               pCity     tElement,
               pState     tElement,
               pZipCode tElement )
IS
BEGIN
FOR i IN pLine1.FIRST..pLine1.LAST
LOOP
INSERT INTO addresses
(line1, line2, line3,
city, state, zipcode)
VALUES
(pLine1(i), pLine2(i), pLine3(i),
pCity(i), pState(i), ZipCode(i));
END LOOP;
END insAddresses
In this case, each array passed into the procedure must have the same length. Unfortunately, not all addresses have values for Line2 or Line3, so more often than not, those arrays are empty. Even though they had been declared with the same length as the Line1 array, the values are all null. When Oracle tries to read from those empty arrays, it throws the following error, "ORA-01403: no data found".
This is how we are passing the parameter to Oracle from C#:
public void AddInputParameter( string pName, string[] pValue)
OracleParameter param = mCom.Parameters.Add(pName,OracleDbType.Varchar2);
     param.Direction = ParameterDirection.Input;
     param.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
     param.Value = pValue;     
     param.Size = pValue.Length;

Similar Messages

  • PL/SQL Associative Array as INPUT Parameter

    Hi,
    Just wondering if anyone out there has a good example of how to get VB.NET (using ODP.NET 9.2.0.4) to pass an Associative Array as an Input parameter to a stored procedure (not for bulk binds)? Specifically, I'm looking for an example of how a VB Strong Typed Collection would be passed through the PLSQLAssociativeArray Collection Type.
    I've managed to get a test to work by passing a 1-D String Array through the ODP.NET layer to the PL/SQL AssociativeArray parameter. But I've had zero success trying to get the Collection from VB through ODP.NET.
    Thanks in advance for any help.
    Todd.

    For example, if I wanted to return a list of customer ids and names into A PLSQL Associative Array, how would I do it. I know how to return a list of customer ids into a PLSQL associative aray using the code below but I have to specify the maximum number of elements and the maximum size of each of the elements. Is there any way around this?
    Dim prmOutCustomerIdList As New OracleParameter
    With prmOutCustomerIdList
    .ParameterName = "oCustomerIdList"
    .CollectionType = OracleCollectionType.PLSQLAssociativeArray
    .OracleDbType = OracleDbType.Varchar2
    .Direction = ParameterDirection.Output
    .Size = 5
    .ArrayBindSize = New Integer(4) {10, 10, 10, 10, 10}
    End With

  • How to pass empty PL/SQL collection?

    I can pass an array as PL/SQL associative array into PL/SQL procedure/block.
    It works perfectly.
    But i can't pass empty array (e.g. new decimal[] {} ) as value - exception raised:
    System.InvalidOperationException:
    "OracleParameter.Value is invalid"
    I can receive empty collection FROM pl/sql, but can i pass empty collection TO pl/sql?

    Unfortunately, there are no any suitable workaround for this problem in thread mentioned above.
    Workaround given by Greg in the thread:
    You can get around it in the meantime by using
    Param1.Value = new string[1]{null};
    Param1.Size=0;Why is that not suitable?
    - Mark

  • Associative Array our only option?

    Hello,
    I'm having a problem accepting associative arrays as the only option I have for getting data from a stored procedure. I have a good reason for not wanting to use ref cursors as I am using the stored procedure to manipulate data which I in turn would like to pass back to VB through the stored procedure and would rather not have to insert he data into a table just to re-select it for a ref cursor.
    My main concern is that with associative arrays I am expected to define the number of return results before I even generate the data. Also from what I can see I am required to set the data length for each and every item in said array one at a time. All this overhead seems like more work than what I would have to do to utilizer a reference cursor. Is there a right way to do this? I would really like to do the most straight forward way I can without the extra processing.

    Hi,
    Here's a blog post of mine that illustrates using pipelined functions and PL/SQL to return results:
    http://oradim.blogspot.com/2007/10/odpnet-tip-using-pipelined-functions.html
    Not sure if that will be helpful in your case, but perhaps it might be a place to start anyway.
    - Mark

  • Associative Array (Object) problems

    Here is the function i'm dealing with
    i'm reading in a delimited string and using indexed arrays to
    break them up and assign the keys and values to an associative
    array in a loop.
    i'm using variables in the loop and the array loads as
    expected in the loop
    but outside the loop, the only key is the variable name and
    the value is undefined
    this is true using dot or array notation, as well as literal
    strings for the keys
    any help is appreciated
    watchSuspendData = function (id, oldval, newval):String {
    //the incoming suspendData string is delimited by the
    semicolon;
    //newval is: firstValue=Yes;captivateKey=1
    var listSuspendData:Array = newval.split(";"); // convert it
    to a list of key/value pairs
    if (listSuspendData.length > 0){
    //line 123: listSuspendData.length is: 2
    for (i=0; i < listSuspendData.length; i++){ //for each
    key/value pair
    var keyValArray:Array = new Array();
    var myNameValue:String = listSuspendData
    //line 127: listSuspendData is: firstValue=Yes
    keyValArray = myNameValue.split("="); // split 'em on the
    equal sign
    var myKey:String = keyValArray[0];
    var myVal:String = keyValArray[1];
    //keyValArray[0] is: firstValue
    //keyValArray[1] is: Yes
    // store the key and the value in associative array
    suspendDataArray.myKey = myVal;
    trace("line 134: suspendDataArray is: " +
    suspendDataArray.myKey);
    // trace is line 134: suspendDataArray is: Yes on the first
    pass and 1 on the second
    //the below loop always returns one array key: myKey and the
    value as undefined
    for(x in suspendDataArray){
    trace("x is: " + x); //x is: myKey
    trace("the val is: " + suspendDataArray.x); //the val is:
    undefined
    } //end for
    return newval;

    on lines 12-13 i assign the key=value pair to string
    variables
    then on lines 17-18 i assign those values to the associative
    array using dot notation
    the trace seems to work there
    the problem is that when the procedure exits the for loop,
    the associative array only has one key (myKey) and no value
    (undefined)
    all the documentation i've read shows using these types of
    arrays with either non-quoted property names like:
    myAssocArray.myKey = "somevalue";
    or
    myAssocArray[myKey] = "somevalue";
    i tried assigning the key/value pairs directly from the
    indexed arrays, but the result was always undefined
    like this:
    suspendDataArray.keyValArray[0] = keyValArray[1]
    or
    suspendDataArray[keyValArray[0]] = keyValArray[1]
    i even tried building a string in the loop and trying to
    assign all the pairs at once using the curly brace
    this is pretty wierd behavior for actionscript or i'm missing
    something basic here
    thanks for looking

  • Associative Array with more than one field - retrieving as output parameter

    Hello,
    I'm developing an C# Application that is showing a datagrid with results from a PL/SQL procedure inside a Package.
    The .net project is in .net 4 and the DB is an oracle 10g.
    I have read the odp.net sample about the associative array. I could successfully pass as an input parameter a string[] and dealing with it inside my PL/SQL procedure.
    Now it become more complex to me because I would like to return an associative array defined like this :
    TYPE r_FinalExtract IS RECORD
    RecordmyTable myTable%ROWTYPE,
    Tel1 varchar2(25),
    Tel1Libelle varchar2(50),
    Tel2 varchar2(25),
    Tel2Libelle varchar2(50),
    Tel3 varchar2(25),
    Tel3Libelle varchar2(50),
    Tel4 varchar2(25),
    Tel4Libelle varchar2(50),
    Tel5 varchar2(25),
    Tel5Libelle varchar2(50),
    Email1 varchar2(50),
    Email1Libelle varchar2(50),
    Email2 varchar2(50),
    Email2Libelle varchar2(50)
    TYPE t_FinalExtract IS TABLE OF r_FinalExtract INDEX BY BINARY_INTEGER;
    You can guess my PL/SQL stored procedure is filling this collection.
    The spec of my procedure :
    PROCEDURE P_SELECTDATA( ptab_ListRef IN t_AssocArrayVarchar2, ptab_Result OUT t_FinalExtract );
    Unfortunately, in my .net project, I don't know how to deal with that.
    I tryed to add p_Result as an output parameter but you have to define the OracleCollectionType for that parameter and the array type is not the good one because my t_FinalExtract is not a simple array...
    I searched over the internet and the only one thread I could find is someone who was doing like me... and finally reply to his own thread 3 months later and said that he had to create CSV lines and return a table of varchar2...
    This is what I will do because I'm loosing time for finding the way to do it with my associative array, but if someone has the solution I would be glad to read it.
    Thanks in advance.

    For PL/SQL records, I would recommend using User-Defined Types (UDTs), rather than associative arrays.
    You can read more on how to use ODP.NET UDTs here:
    http://docs.oracle.com/cd/E20434_01/doc/win.112/e23174/featUDTs.htm#CJAGCAID
    Strictly speaking, ODP.NET doesn't support PL/SQL Records per se. Instead, ODP.NET supports building any generic UDT in the Oracle DB, which covers the effective functionality of a Record.
    If you want to walk through the process of taking a sample DB UDT, generating a .NET custom class, then passing an instance between DB and application, here's a tutorial that shows you how to do that:
    http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/dotnet/userdefinedtypes/userDefinedTypes.htm

  • Associative Arrays, Indexes vs. Full Table Scans

    Hello,
    I just started using ODP.Net to connect my .Net Web Service to our Oracle Database. The reason why I switched to ODP.Net is support for arrays. If I wanted to pass in arrays to the procedure I had to pass it in through a varchar2 in a CSV formatted string.
    ex. "123,456,789"
    So now I'm using ODP.net, passing in PL/SQL Associative Arrays then converting those arrays to nested tables to use within queries.
    ex.
    OPEN OUT_CURSOR FOR
    SELECT COLUMN1, COLUMN2
    WHERE COLUMN_ID IN (SELECT ID FROM TABLE(CAST(ASSOC_ARR_TO_NESTED(IN_ASSOC_ARR) AS NESTED_TBL_TYPE)))
    It uses the array successfully however what it doesn't do is use the index on the table. Running the same query without arrays uses the index.
    My colleague who works more on the Oracle side has posted this issue in the database general section (link below). I'm posting here because it does seem that it is tied to ODP.Net.
    performance - index not used when call from service
    Has anyone ever experienced this before?

    You have to use a cardinality hint to force Oracle to use the index:
    /*+ cardinality(tab 10) */See How to use OracleParameter whith the IN Operator of select statement

  • Process Task Child Table Delete Event passes empty values

    Hi All,
    I'm trying to implement a delete event in a process task for a child table. I am assuming the value to be deleted
    should be getting passing into the adapter but it's passing empty strings instead. The insert event is working fine however.
    Any one else using the delete event that works?
    Thanx
    Fred

    Hi Kevin.
    Any idea how to programmatically access the "old value" variant of a form field?
    It's the sort of thing one needs occasionally when a value changes and some associated capability needs to be updated. The old value specifies what needs to be removed while the new value tells the system what is to be added in its place.
    (It so happens in our environment that we have dozens of these values per user profile, so it would be very painful to store "old" values in a parallel set of fields.)
    Thanks,
    Dan

  • Filling empty java array in C method

    Hi everyone,
    I'm passing to a C method an empty byte array from the Java Side. I want the C method to fill the Java byte array and return it at the end of the method to the java side.
    in the Java side, I have my byte array :
    byte[] myArray = null;
    then I'm passing the array to the C method as
    myMethod(myArray)
    in the C method I'M trying to access the array as follow :
    myMethod(jbyteArray myArray)
    jbyte* tab = *env)->GetByteArrayElements(env, myArray, 0);
    I'm getting an error at runtime. Can somebody help me with that issue please ? Thanks
    Sebastien

    You are not passing a byte array, you are passing null.
    If you want to pass a byte array you first have to create it using the new operator:
    byte[] myArray = new byte[theSizeOfTheArray];
    myMethod(myArray);If you want the JNI code to create the array, that is fine also, but in that case the native method would probably have to return the array instead of void.

  • How do u create a datatable from PLSQL Associative Arrays returned from SP

    Using C# 4.0 ODP.NET 11g, vs2010 on Windows XP.
    Have a procedure that takes two input values and returns 35 PL\SQL Associative Arrays (pl/sql tables). I am currently able to call the proc and have it returned the values. i end up with 35 arrays each 35 elements in length.
    I want to create a datatable from them but am at a lost on how to do so.
    This what i have
    Oracle.DataAccess.Client.OracleCommand oCommand = new Oracle.DataAccess.Client.OracleCommand();
    oCommand.CommandText = ProcName;
    oCommand.CommandType = CommandType.StoredProcedure;
    //Input Parameters
    OracleParameter param1 = oCommand.Parameters.Add("p_orderid",OracleDbType.Int32);
    param1.Direction = ParameterDirection.Input;
    param1.Value = OrderID;
    OracleParameter param2 = oCommand.Parameters.Add("p_testinstanceid", OracleDbType.Int32);
    param2.Direction = ParameterDirection.Input;
    param2.Value = TestInstanceID;
    //Output Parameters
    OracleParameter param3 = oCommand.Parameters.Add("program_id", OracleDbType.Int32);
    param3.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
    param3.Direction = ParameterDirection.Output;
    param3.Size = 50;
    OracleParameter param4 = oCommand.Parameters.Add("normyear", OracleDbType.Varchar2);
    param4.CollectionType = OracleCollectionType.PLSQLAssociativeArray;
    param4.Direction = ParameterDirection.Output;
    param4.Size = 50;
    param4.ArrayBindSize = new int[50];
    // set the bind size value for each element
    for (int i = 0; i < 50; i++)
    param4.ArrayBindSize[i] = 10;
    ...33 more output parameters all PLSQLAssociativeArray type
    oCommand.ExecuteNonQuery();
    OracleDataAdapter da = new OracleDataAdapter(oCommand);
    //Fill the DataTable
    da.Fill(dt);
    The datatable is empty. What am i doing wrong? Or this there a better way to get the output values to end up in a datatable. Note that when i examine the parameters in oCommand i see that they all the the right out values.

    I have multiple where conditions which needs the same subqueryThat is where the Subquery Factoring Clause comes in handy, because then
    »Oracle Database optimizes the query by treating the query name as either an inline view or as a temporary table«
    with temp as (
    subquery
    select 1
      from table1
    where col1 in (select * from temp)
       and col2 in (select * from temp)
       and col3 in (select * from temp)

  • Correct syntax with associative arrays??

    Hi All,
    I'm doing something wrong with my syntax. I'm trying to grab
    data out of an associative array, but I'd like to be able to
    dynamically pass that array name on a button press. Can someone
    help me out with the correct syntax. I can easily setup a switch
    statement and copy the code and hard code each associative array
    name three times...but I have that whole block below 3 times. It
    works...but it's very ugly. I'd like to just pass the 'phase'
    dynamically since they all use the same code setup, just different
    array names. Any help would be greatly appreciated. - Grant

    Maybe you should start learning AS3, its much more easier to
    use an xml file.

  • Associative array related problem

    Hi All,
    When I am trying to use assotiative array in a select statement I recieve the following error:
    ORA-06550: line 9, column 22:
    PLS-00201: identifier 'COL1' must be declared
    ORA-06550: line 9, column 22:
    PLS-00201: identifier 'COL1' must be declared
    ORA-06550: line 9, column 10:
    PL/SQL: ORA-00904: : invalid identifier
    ORA-06550: line 9, column 3:
    PL/SQL: SQL Statement ignored
    Here is the example
    --create table MyTable (col1 varchar2(255), col2 varchar2(255))
    declare
      type m_ttMyTable
        is table of MyTable%rowtype index by MyTable.col1%type;
      m_tMyTable                   m_ttMyTable;
      m_sCol2 varchar2(255);
    begin
      select m_tMyTable (col1).col2  /* works with ocntant: select m_tMyTable */('col1').col2
        into m_sCol2
      from MyTable
      where rownum = 1;
    end;
    --drop table MyTableAny ideas how to workaround this?
    Thanks

    The only collection types SQL can query are ones defined in SQL using CREATE TYPE. That excludes associative arrays, as they are PL/SQL-only constructs. I'd recommend a nested table collection.
    Some more suggestions:
    www.williamrobertson.net/documents/collection-types.html

  • Associative Array error

    I am using a couple associative arrays in my code and comparing the data in one, and if it is an asterisk, I change it to use the data in the other. Here is the meat of my code. I am running into an error at the bolded line saying I have too many values, which I don't understand because the code is the exact same as the block of code right before it where I populate the first array. FYI, the table it is pulling from only has one row. The error is listed below the code.
    Code
    DECLARE
    TYPE refresh_file_t IS TABLE OF test.loading_dock%ROWTYPE ;
    refresh_data refresh_file_t ;
    prospect_data refresh_file_t ;
    TYPE CV_TYPE IS REF CURSOR ;
    c_id CV_TYPE ;
    v_id NUMBER(10) ;
    v_phone VARCHAR2(10) ;
    v_project VARCHAR2(10) ;
    BEGIN
    OPEN c_id FOR
    'SELECT id
    FROM test.loading_dock
    WHERE rownum = 1' ;
    LOOP
    FETCH c_id INTO v_id ;
    EXIT WHEN c_id%NOTFOUND ;
    SELECT * BULK COLLECT
    INTO refresh_data
    FROM test.loading_dock
    WHERE id = v_id ;
    SELECT * BULK COLLECT
    INTO prospect_data
    FROM test.prospects
    WHERE id_number = v_id ;
    IF refresh_data(1).home_phone = '*' THEN
    v_phone := prospect_data(1).phone ;
    ELSE
    v_phone := refresh_data(1).home_phone ;
    END IF ;
    DBMS_OUTPUT.PUT_LINE(v_phone) ;
    END LOOP ;
    CLOSE c_id ;
    END ;
    Error
    ORA-06550: line 29, column 13:
    PL/SQL: ORA-00913: too many values
    ORA-06550: line 27, column 13:
    PL/SQL: SQL Statement ignored
    ORA-06550: line 34, column 46:
    PLS-00302: component 'PHONE' must be declared
    ORA-06550: line 34, column 13:
    PL/SQL: Statement ignored
    06550. 00000 - "line %s, column %s:\n%s"

    Collection prospect_data is of type refresh_file_t, which is a table of records of test.loading_dock%TYPE. Most likely tables test.loading_dock and test.prospects have different structure - test.prospects has fewer columns. So when you try to fetch from test.prospects into prospect_data you get the error Try replacing
    prospect_data refresh_file_t ;with
    TYPE prospect_data_t IS TABLE OF test.prospects%ROWTYPE ;
    prospect_data prospect_data_t ;SY.

  • Associative Array Question

    Hi All,
    I've searched through this forum trying to find information I'm needing on associative arrays with a varchar2 index without luck. What I'm looking for is a way to get the index or "key" values of the array without knowing what they are. Meaning, I wouldn't have to know the index value when designing the array but would be able to utilize them values at runtime. For those familiar with Java it would be like calling the keySet() method from a Map object.
    So, if I have an array of TYPE COLUMN_ARRAY IS TABLE OF VARCHAR2(4000) INDEX BY VARCHAR2(100) is there any way to dynamically get the index values without knowing what they are?
    Any help is appreciated.
    Thanks

    Thanks for the response.
    I am aware of using FIRST and NEXT for iterating the array but can I extract the index value of the current element into a variable when I don't know what the index value is at runtime ?
    Thanks

  • Associative Array vs Table Scan

    Still new to PL/SQL, but very keen to learn. I wondered if somebody could advise me whether I should use a collection (such as an associative array) instead of repeating a table scan within a loop for the example below. I need to read from an input table of experiment data and if the EXPERIMENT_ID does not already exist in my EXPERIMENTS table, then add it. Here is the code I have so far. My instinct is that it my code is inefficient. Would it be more efficient to scan the EXPERIMENTS table only once and store the list of IDs in a collection, then scan the collection within the loop?
    -- Create any new Experiment IDs if needed
    open CurExperiments;
    loop
    -- Fetch the explicit cursor
    fetch CurExperiments
    into vExpId, dExpDate;
    exit when CurExperiments%notfound;
    -- Check to see if already exists
    select count(id)
    into iCheckExpExists
    from experiments
    where id = vExpId;
    if iCheckExpExists = 0 then
    -- Experiment ID is not already in table so add a row
    insert into experiments
    (id, experiment_date)
    values(vExpId, dExpDate);
    end if;
    end loop;

    Except that rownum is assigned after the result set
    is computed, so the whole table will have to be
    scanned.really?
    SQL> explain plan for select * from i;
    Explained.
    SQL> select * from table( dbms_xplan.display );
    PLAN_TABLE_OUTPUT
    Plan hash value: 1766854993
    | Id  | Operation         | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT  |      |   910K|  4443K|   630   (3)| 00:00:08 |
    |   1 |  TABLE ACCESS FULL| I    |   910K|  4443K|   630   (3)| 00:00:08 |
    8 rows selected.
    SQL> explain plan for select * from i where rownum=1;
    Explained.
    SQL> select * from table( dbms_xplan.display );
    PLAN_TABLE_OUTPUT
    Plan hash value: 2766403234
    | Id  | Operation          | Name | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |      |     1 |     5 |     2   (0)| 00:00:01 |
    |*  1 |  COUNT STOPKEY     |      |       |       |            |          |
    |   2 |   TABLE ACCESS FULL| I    |     1 |     5 |     2   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter(ROWNUM=1)
    14 rows selected.

Maybe you are looking for

  • Network Drives Missing

    Mapping drives on boot up VBS logon script mapping drives via the DFS name Only appears to affect laptops All laptop have offline files for their U drive Some laptops have hotfix KB2705233 installed, however  this did work with x86 version of windows

  • Problems passing a nested table or Varray as a parameter

    Hi, could some one please show me the code for passing a varray or a table as a parameter in a PL/SQL function or procedure. I have tried a number of ways but am not getting anywhere fast. A small bit of sample code that shows a function that takes a

  • Photos from laptop to mac

    *Hello* **I recently got an imac. I am trying to put my photos from my old laptop to the imac. I can't use the usb or the cd dvd drive on the laptop to transfer my photos. I have tried emailing the photos. But my email only lets me email 4 photos at

  • Premiere 6.5 isn't letting me get it's updates.

    I love Premiere 6.5 and still have it running on my Win7 32-bit machines (runs great) and have a dual-boot xp partition on my 64-bit 7 machines.  Anyway, I had to reinstall my xp from a backup and when I try to do the updates for Premiere 6.5 it give

  • Extension is accessible even after it is disabled from Extension Manager CC (MAC only)

    Hello, I am using Extension Manager CC to install InDesign CC plugins on MAC. After successful installation if I disable the extension from Extension manager, it is still accessible in InDesign. Any suggestions? Note: Checked extension for BasicDialo