Improper result when number table is used to substitute the "IN" clause in oracle

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • sarith sutha

    Improper result when number table is used to substitute the "IN" clause in oracle

    Hi Guys

    Need a help i am facing a sporadic issue when executing the query
    using nested table of numbers

    Here are the things which i did

    1. I created a type as
    CREATE TYPE NUMBERTABLE AS TABLE OF NUMBER;

    2.In the JDBC Code
    i declare a long[] longArray and populate the long array by going
    through some query

    3. Then i execute the following query
    String str = "select id from table1 where id in (SELECT * FROM TABLE
    (SELECT CAST(? AS NUMBERTABLE ) FROM DUAL))

    OraclePreparedS tatement pstmt = conn.prepareSta tement(str)

    //Create the ArrayDescriptor and array object
    ArrayDescriptor desc = ArrayDescriptor .createDescript or("NUMBERTABL E "
    ,conn);
    ARRAY array_to_pass = new ARRAY(desc, conn, longArray );
    pstmt.setARRAY( 1,array_to_pass );

    //Execute the Query

    ResultSet rs = pstmt.executeQu ery();

    while(rs.next() )
    {
    System.out.prin tln("**** Id is : " + rs.getLong(1));
    }

    4.Guys the problem i am facing is that query is not displaying all the
    results

    For Ex:
    if the longArray = {100,101,102,10 3,104} , if this array is bound and
    the query executed, sometimes not all the 5 values are displayed ,
    like this one happened to me

    "**** Id is : 100
    "**** Id is : 101
    "**** Id is : 102

    103,104 were not displayed even though the longArray contained them
    ,Plz dont suggest me to use "IN" clause instead since the longarray
    size may exceed 1000 entries

    Can anyone there tell why the last 2 entries are not
    displayed(chopp ed),guys my work is stuck up ,pl help

    sarith
Working...