Oracle Array

Hi,
I need to know all about Oracle Arrays. Where can I find some practical examples of working with Arrays in Oracle?
For e.g. Example programs having definition, declaration, manipulating the array
Regards,
Lostworld

I have given some basic examples. You can try it and learn
BANNER
Oracle Database 11g Express Edition Release 11.2.0.2.0 - Production
PL/SQL Release 11.2.0.2.0 - Production
CORE    11.2.0.2.0      Production
TNS for 32-bit Windows: Version 11.2.0.2.0 - Production
NLSRTL Version 11.2.0.2.0 - Production
Simple Varray type:-
CREATE OR REPLACE PROCEDURE proc_arraytest
AS
----- Varray Definition
TYPE var_details IS VARRAY(14) OF emp.ename%TYPE;
----- Varray Declaration
v_vardetails var_details := var_details();
v_position NUMBER := 0;
BEGIN
FOR i IN (SELECT ename FROM emp)
  LOOP
   v_position := v_position+1;
   v_vardetails.EXTEND;
   ----- Manipulating into VARRAY
   v_vardetails(v_position) := i.ename;
   END LOOP;
  ---- Printing VARRAY values
  FOR j in 1..v_vardetails.COUNT
   LOOP
    DBMS_OUTPUT.PUT_LINE(v_vardetails(j));
   END LOOP;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END proc_arraytest;
EXEC proc_arraytest;
Varray with record type:-
CREATE OR REPLACE PROCEDURE proc_arrayrectest
AS
----- Record Definition
TYPE rec_details IS RECORD (empno emp.empno%TYPE,
                             ename emp.ename%TYPE,
                             deptno emp.deptno%TYPE,
                             dname  dept.dname%TYPE
----- Varray Definition
TYPE var_details IS VARRAY(20) OF rec_details;
----- Varray Declaration
v_vardetails var_details := var_details();
v_position NUMBER := 0;
BEGIN
FOR i IN (SELECT empno,ename,e.deptno deptno,dname FROM emp e,dept d WHERE e.deptno = d.deptno)
  LOOP
   v_position := v_position+1;
   v_vardetails.EXTEND;
   ----- Manipulating into VARRAY
   v_vardetails(v_position).empno := i.empno;
   v_vardetails(v_position).ename := i.ename;
   v_vardetails(v_position).deptno := i.deptno;
   v_vardetails(v_position).dname := i.dname;
   END LOOP;
  ---- Printing VARRAY values
  FOR j in 1..v_vardetails.COUNT
   LOOP
    DBMS_OUTPUT.PUT_LINE(v_vardetails(j).empno||','||
                         v_vardetails(j).ename||','||
                         v_vardetails(j).deptno||','||
                         v_vardetails(j).dname);
   END LOOP;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END proc_arrayrectest;
EXEC proc_arrayrectest;
Simple Varray type With Bulk collect:-
CREATE OR REPLACE PROCEDURE proc_arraybulktest
AS
----- Varray Definition
TYPE var_details IS VARRAY(14) OF emp.ename%TYPE;
----- Varray Declaration
v_vardetails var_details;
v_position NUMBER := 0;
BEGIN
---- Manipulating into Varray using bulk collect
SELECT ename BULK COLLECT INTO v_vardetails FROM emp;
  ---- Printing VARRAY values
  FOR j in 1..v_vardetails.COUNT
   LOOP
    DBMS_OUTPUT.PUT_LINE(v_vardetails(j));
   END LOOP;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END proc_arraybulktest;
EXEC proc_arraybulktest;
Varray with record type(Bulk Collect):-
CREATE OR REPLACE PROCEDURE proc_arrayrecbulktest
AS
----- Record Definition
TYPE rec_details IS RECORD (empno emp.empno%TYPE,
                             ename emp.ename%TYPE,
                             deptno emp.deptno%TYPE,
                             dname  dept.dname%TYPE
----- Varray Definition(You need to mention the size of varray.. Here is 20)
TYPE var_details IS VARRAY(20) OF rec_details;
----- Varray Declaration
v_vardetails var_details := var_details();
v_position NUMBER := 0;
BEGIN
---- Manipulating into Varray using bulk collect
SELECT empno,
        ename,
        e.deptno deptno,
        dname BULK COLLECT INTO v_vardetails
FROM emp e,
     dept d
WHERE e.deptno = d.deptno;
  ---- Printing VARRAY values
  FOR j in 1..v_vardetails.COUNT
   LOOP
    DBMS_OUTPUT.PUT_LINE(v_vardetails(j).empno||','||
                         v_vardetails(j).ename||','||
                         v_vardetails(j).deptno||','||
                         v_vardetails(j).dname);
   END LOOP;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END proc_arrayrecbulktest;
EXEC proc_arrayrecbulktest;
------ We have forall for bulk insert.
Varray with FORALL:-
CREATE OR REPLACE PROCEDURE proc_arrayrecbulkforalltest
AS
----- Record Definition
TYPE rec_details IS RECORD (empno emp.empno%TYPE,
                             ename emp.ename%TYPE,
                             deptno emp.deptno%TYPE,
                             dname  dept.dname%TYPE
----- Varray Definition(You need to mention the size of varray.. Here is 20)
TYPE var_details IS VARRAY(20) OF rec_details;
----- Varray Declaration
v_vardetails var_details := var_details();
v_position NUMBER := 0;
BEGIN
---- Manipulating into Varray using bulk collect
SELECT empno,
        ename,
        e.deptno deptno,
        dname BULK COLLECT INTO v_vardetails
FROM emp e,
     dept d
WHERE e.deptno = d.deptno;
  ----Bulk insert
  FORALL i in 1..v_vardetails.COUNT
   INSERT INTO test_empdet(empno,
                           ename,
                           deptno,
                           dname
                 VALUES (v_vardetails(i).empno,
                         v_vardetails(i).ename,
                         v_vardetails(i).deptno,
                         v_vardetails(i).dname
COMMIT;
EXCEPTION
WHEN OTHERS THEN
RAISE;
END proc_arrayrecbulkforalltest;
EXEC proc_arrayrecbulkforalltest;

Similar Messages

  • Oracle Arrays and getVendorConnection API and Class Cast Exception

    I 've gone through various threads relating to the topic of Oracle Arrays and the getVendorConnecton API call to avoid the class Cast Exception.. i ve used all these but am still facing the problem...
    I would appreciate it if some one could resolve the following queries :
    I am using Weblogic 8.1 SP5 with oracle 8i
    1. I read that the need to use the getVendorConnection API to make pl/sql proc calls with oracle arrays from the WL Server wont be required to avoid classCastException...
    I tried to use the connection from the WL connection pool ..but it didnot work....I used the getVendorConnection API ..which also doesnot seem to work..
    I got the Heurisitc Hazard exception...I used the Oracle 9i driver ie ojdbc14.jar ...after this the exception is not coming but still the code doesnt seem to work...
    the snippet of the code is pasted below :
    ~~~~~~~~~~~~~~~~~~~~~~~code is : ~~~~~~~~~~~~~~~~~~~
    /*below :
    logicalCon is the Connection from the WL connection pool
    JDBCcon is the JDBC connection. */
    <div> try </div>
    <div>{ </div>
    <div>
    <b>vendorConn</b> = ((WLConnection)logicalCon).getVendorConnection();
    </div>
    <div>
    //Calling the procedure
    </div>
    <div>
    //java.util.Map childMap1 = JDBCcon.getTypeMap();
    </div>
    <div>
    java.util.Map childMap1 = <b>vendorConn</b>.getTypeMap();
    </div>
    <div>
    childMap1.put("SST_ROUTE_ENTRY", Class.forName("svm.stport.ejb.StaticRouteEntry"));
    </div>
    <div>
    //JDBCcon.setTypeMap(childMap1);
    <b>vendorConn</b>.setTypeMap(childMap1);
    </div>
    <div>
    // Create an oracle.sql.ARRAY object to hold the values
    </div>
    <div>
    /*oracle.sql.ArrayDescriptor arrayDesc1 = oracle.sql.ArrayDescriptor.createDescriptor("SST_ROUTE_ENTRY_ARR", JDBCcon); */
    </div>
    <div>
    oracle.sql.ArrayDescriptor arrayDesc1 =
    oracle.sql.ArrayDescriptor.createDescriptor("SST_ROUTE_ENTRY_ARR", <b>vendorConn</b>); // here if i use the JDBCcon it works perfectly.... <u>^%^%^%</u>
    </div>
    <div>
    code to fill in the sst route entry array....
    .....arrayValues1 */
    </div>
    <div>
    /* oracle.sql.ARRAY array1 = new oracle.sql.ARRAY(arrayDesc1, JDBCcon, arrayValues1); */
    </div>
    <div>
    oracle.sql.ARRAY array1 = new oracle.sql.ARRAY(arrayDesc1, <b>vendorConn</b>, arrayValues1);
    </div>
    <div>
    callStatement = logicalCon.prepareCall( "? = call procName(?, ?, ?)");
    </div>
    <div>
    /* ..code to set the ?s ie array1 */
    </div>
    <div>
    callStatement.execute();
    </div>
    <div>
    }catch(Exceptio e){
    </div>
    <div>
    }</div>
    <div>
    finally </div>
    </div>{</div>
    <div>System.out.println(" I ve come to finally"); </div>
    <div>}</div>
    <div>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~code snippet ends here ~~~~~~~~~~~~~~``
    </div>
    I have observed that the control immediately comes to the finally block after the call to the createDescriptor line above with <u>^%^%^%</u> in the comment. If i use the JDBCCon in this line...it works perfectly fine.
    Any pointers to where anything is getting wrong.
    I have jst set the vendorCon to null in the end of the file and not closed it. Subsequently i have closed the logicalCon. This has been mentioned in some of the thread in this forum also.
    Thanks,
    -jw

    Jatinder Wadhwa wrote:
    I 've gone through various threads relating to the topic of Oracle Arrays and the getVendorConnecton API call to avoid the class Cast Exception.. i ve used all these but am still facing the problem...
    I would appreciate it if some one could resolve the following queries :
    I am using Weblogic 8.1 SP5 with oracle 8i
    1. I read that the need to use the getVendorConnection API to make pl/sql proc calls with oracle arrays from the WL Server wont be required to avoid classCastException...
    I tried to use the connection from the WL connection pool ..but it didnot work....I used the getVendorConnection API ..which also doesnot seem to work..
    I got the Heurisitc Hazard exception...I used the Oracle 9i driver ie ojdbc14.jar ...after this the exception is not coming but still the code doesnt seem to work...
    the snippet of the code is pasted below :
    ~~~~~~~~~~~~~~~~~~~~~~~code is : ~~~~~~~~~~~~~~~~~~~Hi. Show me the whole exception and stacktrace if you do:
    try
    vendorConn = ((WLConnection)logicalCon).getVendorConnection();
    java.util.Map childMap1 = vendorConn.getTypeMap();
    childMap1.put("SST_ROUTE_ENTRY" Class.forName("svm.stport.ejb.StaticRouteEntry"));
    vendorConn.setTypeMap(childMap1);
    oracle.sql.ArrayDescriptor arrayDesc1 =
    oracle.sql.ArrayDescriptor.createDescriptor("SST_ROUTE_ENTRY_ARR",
    vendorConn);
    oracle.sql.ARRAY array1 = new oracle.sql.ARRAY(arrayDesc1, vendorConn, arrayValues1);
    callStatement = logicalCon.prepareCall( "? = call procName(? ? ?)");
    callStatement.execute();
    }catch(Exception e){
    e.printStackTrace();
    finally
    try{logicalCon.close();}catch(Exception ignore){}
    System.out.println(" I ve come to finally");
    /*below :
    logicalCon is the Connection from the WL connection pool
    JDBCcon is the JDBC connection. */
    <div> try </div>
    <div>{ </div>
    <div>
    <b>vendorConn</b> = ((WLConnection)logicalCon).getVendorConnection();
    </div>
    <div>
    //Calling the procedure
    </div>
    <div>
    //java.util.Map childMap1 = JDBCcon.getTypeMap();
    </div>
    <div>
    java.util.Map childMap1 = <b>vendorConn</b>.getTypeMap();
    </div>
    <div>
    childMap1.put("SST_ROUTE_ENTRY", Class.forName("svm.stport.ejb.StaticRouteEntry"));
    </div>
    <div>
    //JDBCcon.setTypeMap(childMap1);
    <b>vendorConn</b>.setTypeMap(childMap1);
    </div>
    <div>
    // Create an oracle.sql.ARRAY object to hold the values
    </div>
    <div>
    /*oracle.sql.ArrayDescriptor arrayDesc1 = oracle.sql.ArrayDescriptor.createDescriptor("SST_ROUTE_ENTRY_ARR", JDBCcon); */
    </div>
    <div>
    oracle.sql.ArrayDescriptor arrayDesc1 =
    oracle.sql.ArrayDescriptor.createDescriptor("SST_ROUTE_ENTRY_ARR", <b>vendorConn</b>); // here if i use the JDBCcon it works perfectly.... <u>^%^%^%</u>
    </div>
    <div>
    code to fill in the sst route entry array....
    .....arrayValues1 */
    </div>
    <div>
    /* oracle.sql.ARRAY array1 = new oracle.sql.ARRAY(arrayDesc1, JDBCcon, arrayValues1); */
    </div>
    <div>
    oracle.sql.ARRAY array1 = new oracle.sql.ARRAY(arrayDesc1, <b>vendorConn</b>, arrayValues1);
    </div>
    <div>
    callStatement = logicalCon.prepareCall( "? = call procName(?, ?, ?)");
    </div>
    <div>
    /* ..code to set the ?s ie array1 */
    </div>
    <div>
    callStatement.execute();
    </div>
    <div>
    }catch(Exceptio e){
    </div>
    <div>
    }</div>
    <div>
    finally </div>
    </div>{</div>
    <div>System.out.println(" I ve come to finally"); </div>
    <div>}</div>
    <div>
    ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~code snippet ends here ~~~~~~~~~~~~~~``
    </div>
    I have observed that the control immediately comes to the finally block after the call to the createDescriptor line above with <u>^%^%^%</u> in the comment. If i use the JDBCCon in this line...it works perfectly fine.
    Any pointers to where anything is getting wrong.
    I have jst set the vendorCon to null in the end of the file and not closed it. Subsequently i have closed the logicalCon. This has been mentioned in some of the thread in this forum also.
    Thanks,
    -jw

  • Oracle Array Fetches

    Hi,
    I've been reading information about Oracle driver advanced features, and I've
    come across Oracle Array Fetches.
    We we're thinking on using this, but we have several doubts. When you create
    the Connection, it must be created using
    myDriver.connect, but we wanted to make all connections using Datasource.
    Is it possible to create connections using
    Datasource and use Oracle Array Fetches?
    If we don't use weblogic.oci.cacheRows, which value will it use? If it's 100,
    for example, does it mean that every
    100 records, it will perform a new fetch instruction that will ask for those
    new 100 records to DBMS?
    Which is the most accurate value for it? A big one to make DBMS work less
    or a short one for not overwhelming weblogic?
    Thanks in advance

    Hi ,
    One cause for that error is there is no type definition for formaters we are using.EX money and date formaters.
    thanks

  • Oracle Array from J++

    I am trying to access oracle array from J++ and couldn't have any luck. Can any one help me and show me some code. i want to access array (String array) from oracle stored procedure using j++ . thanks
    [email protected]

    I'm able to send arrays from flex but to a web service
    written in ASP.Net, i dont know i this could help you.

  • Trying to pass Oracle array/object type to Java

    I have a Java class with two inner classes that are loaded into Oracle:
    public class PDFJ
        public static class TextObject
            public String font_name;
            public int font_size;
            public String font_style;
            public String text_string;
        public static class ColumnObject
            public int left_pos;
            public int right_pos;
            public int top_pos;
            public int bottom_pos;
            public int leading;
            public TextObject[] column_texts;
    }I have object types in Oracle as such that bind to the Java classes:
    CREATE OR REPLACE TYPE "PROGRAMMER"."PDFJ_TEXT" AS OBJECT
    EXTERNAL NAME 'PDFJ$TextObject'
    LANGUAGE JAVA
    USING SQLData(
      "FONT_NAME" VARCHAR2(25) EXTERNAL NAME 'font_name',
      "FONT_SIZE" NUMBER EXTERNAL NAME 'font_size',
      "FONT_STYLE" VARCHAR2(1) EXTERNAL NAME 'font_style',
      "TEXT_STRING" VARCHAR2(4000) EXTERNAL NAME 'text_string'
    CREATE OR REPLACE TYPE "PROGRAMMER"."PDFJ_TEXT_ARRAY" AS
      TABLE OF "PROGRAMMER"."PDFJ_TEXT";
    CREATE OR REPLACE TYPE "PROGRAMMER"."PDFJ_COLUMN" AS OBJECT
    EXTERNAL NAME 'PDFJ$ColumnObject'
    LANGUAGE JAVA
    USING SQLData(
      "LEFT_POS" NUMBER EXTERNAL NAME 'left_pos',
      "RIGHT_POS" NUMBER EXTERNAL NAME 'right_pos',
      "TOP_POS" NUMBER EXTERNAL NAME 'top_pos',
      "BOTTOM_POS" NUMBER EXTERNAL NAME 'bottom_pos',
      "LEADING" NUMBER EXTERNAL NAME 'leading',
      "COLUMN_TEXTS" "PROGRAMMER"."PDFJ_TEXT_ARRAY" EXTERNAL NAME 'column_texts'
    CREATE OR REPLACE TYPE "PROGRAMMER"."PDFJ_COLUMN_ARRAY" AS
        TABLE OF "PROGRAMMER"."PDFJ_COLUMN";
    /I successfully (as far as I know) build a PDFJ_COLUMN_ARRAY object in a PL/SQL procedure. The PDFJ_COLUMN_ARRAY contains PDFJ_COLUMN objects; each of those objects contains a PDFJ_TEXT_ARRAY of PDFJ_TEXT objects (Example: pdf_column_array(i).pdf_text_array(i).text_string := 'something';). In this procedure, I pass this PDFJ_COLUMN_ARRAY as a parameter to a Java function. I assume the Java function parameter is supposed to be a oracle.sql.ARRAY object.
    I cannot figure out how to decompose this generic ARRAY object into a ColumnObject[] array. I also tried Googling and searching the forums, but I can't figure out matching search criteria. I was wondering if anyone here knows anything about passing user-defined Oracle type objects to a Java function and retrieving the user-defined Java class equivalents that they are supposedly mapped to--especially a user-defined array type of user-defined object types containing another user-defined array type of user-defined object types.

    Ok. I will try asking on the JDBC forum. So, don't
    flame me for cross-posting. :PWe won't, if over there you just post basically a
    link to this one.
    sigh Guess what, he did it the flame-deserving way. It's crossposted at:
    http://forum.java.sun.com/thread.jspa?threadID=602805
    <flame level="mild">Never ceases to amaze me how people don't think that posting a duplicate rather than a simple link isn't wasteful, as people could end up answering in both of them, not seeing each other's answers</flame>

  • Oracle Arrays support in WLS7.0

    Getting a ClassCast Exception when using Oracle.jdbc.ArrayDescriptor.createDescritor("array",conn)

    Hi,
    If you don't set the datatype (i.e. leave it as "unknown", or set it back to "unknown"), it will generate
    TEST_V AS ( CASE WHEN EVENT_NAME = 'XXXX' THEN 'MMMM' ELSE 'KKKK' END )
    The Oracle 11gR2 documentation for the virtual_column_definition clause notes that "The keyword VIRTUAL is optional and for syntactic clarity."
    So the fact that Data Modeler does not output the keyword VIRTUAL does not make any difference to the effect of the SQL statement.
    David

  • Troubleshooting Oracle array type names in JDBC calls

    Hi,
    There are several threads in this forum about people having trouble with the array SQL type names that the Oracle JDBC driver recognizes (e.g., in a call setting up PLSQL procedure OUT parameters like "call.registerOutParameter(1, Types.ARRAY, "VARCHAR_NESTED_TAB_TYP");"). I've seen at least the following threads:
    * vinay saini's "accessing package defined datatypes in oracle from JDBC" thread (Re: Heterogeneous Connectivity to SQL Server from 8.0.5
    * fwelland's "PL/SQL Tables as IN parameters???" thread (Re: entity relationship/model of database diagram
    * Ernesto Marquina's "Table Type as OUT parameter" thread (Re: Changing namespace
    * Nazneen Nahid's "Oracle PL/SQL type defined within a package can't be passed from JAVA" thread (Re: BI Beans Graph in JSp
    * vinay saini's "mapping Table/VARRAY data type to JDBC data type" thread (Re: 9.0.3 unable to find session bean for AM
    I'm stuck in the middle of this myself, and found that something useful to look at is the PLSQL procedure that the driver uses to determine whether the type is there. You can run the following test PLSQL block with your schema name and type name to check on the database side whether it will work:
    declare
    schemaname varchar(255);
    typename varchar(255);
    typoid raw(255);
    version integer;
    tds long raw;
    lds long raw;
    begin
    schemaname := 'MKT2_SMD9';
    typename := 'VARCHAR_NESTED_TAB_TYP';
    dbms_output.put_line('Result for '||schemaname||','||typename||'='||
    dbms_pickler.get_type_shape(schemaname, typename, typoid, version, tds, lds));
    end;
    If the procedure returns 0, then the JDBC code should have no trouble picking up the array type and handling your call. If the procedure returns a nonzero number, the JDBC code using the same schemaname and typename will probably fail. This at least allows you to try a number of different schema and type names with the application and driver layers eliminated. Unfortunately, I have no idea how get_type_shape works, and it doesn't seem to be documented in Oracle's 9i docs, so I can't shed any light on why some things work and others don't.
    Jim

    I guess, in hibernate, in order to make it serialized object, try using set/collection implementation.

  • Oracle Array Update and sqlerrd[2] in PROC/C++ HELP!!!!!!!!!!!

    Coding an array update in Pro C/C++ in an Oracle 8.0.5 environment
    (don't ask...). Having trouble when errors occur in one of the
    updates...
    If I have an array of 5 updates, (EXEC SQL FOR 5...), with the first
    update on a non-existant row, I expect Oracle to stop processing on
    the first element of the array, and return sqlerrd[2] = 1. What I
    get is sqlerrd[2] = 4 (IE, it processed successfully array elements
    2-5)
    If the 3rd element of the array is bad, sqlerrd[2] = 3, which is what
    I would expect (3 rows processed, stopped processing after 3rd (bad)
    element.
    It seems that Oracle stops if an error occurs in the middle of the
    array, but not for the first element?
    If the 5th element bombs, sqlerrd2] = 4, telling me 4 rows were
    processed. How do I know if its stopped on the 4th becuase 4 was bad,
    vsprocessed 4 good and one bad?
    I am lost....
    I had assumed 2 things:
    1 Oracle stops processing and array when an error occurs
    2 sqlerrd[2] tells me how many rows it processed not including(?) the
    one in error.
    The observed behavior seems inconsistant....

    This is really the same situation as if you were trying to build different binaries using different versions of Pro C (which is in fact what you are trying to do). The Pro C compilation system is quite complex and it uses a lot of environment variables and so on. You really need to isolate both build environments so that each environment only has the necessary environment setup and there is no cross-contamination between them.
    Chris

  • How to pass a multidimensional array to an Oracle procedure?

    How can I pass a multidimensional array to oracle array?
    Thanx in anticipation,

    Look in to passing user defined type back and forth to Oracle. Any type that oracle supports, you can constract on the java side and send it across. Look into the SQLData class.

  • Java. ARRAY: oracle-character-set-171

    Hello!
    I need send array of String to Oracle stored procedure.
    I make Oracle ARRAY type ('CREATE OR REPLACE TYPE A_VALUES AS VARRAY(20) OF CHAR(500)').
    Simple my java-code:
    1: ArrayDescriptor descrVal = new ArrayDescriptor("A_VALUES", con);
    2: ARRAY A_VALUES = new ARRAY(descrVal, con, values);
    When to run 2: line to arrise exception:
    java.sql.SQLException: Non supported character set: oracle-character-set-171.
    Why?

    user8478825 wrote:
    Guys please reactA reaction - don't post new questions on old threads.

  • DAO in Websphere calling Oracle SP with array input params

    Hi,
    We have a complex Oracle stored procedure which gets called by the DAO in Websphere 5.1.
    The stored procedure takes couple of input array.
    Code snippet -
    CallableStatement cstmt = con.prepareCall("{call pkg_name.ap_name( ?,?,?,?,?,?,?,?,? )}");
    ArrayDescriptor desc = ArrayDescriptor.createDescriptor("STRING_VARRAY", con);
    ARRAY arr1 = new ARRAY(desc, con, strArray);
    cstmt.setArray(1, arr1);
    I get this exception when trying to create Oracle array desciptor -
    java.lang.ClassCastException: com/ibm/ws/rsadapter/jdbc/WSJdbcConnection incompatible with oracle/jdbc/OracleConnection
    How can I get a OracleJdbcConnection object from WSJdbcConnection?
    Is there any way to do this using the WS Jdbc classes?
    Is there any other way to pass an array to a callable statement?
    TIA.
    - vineet

    Hi,
    We have a complex Oracle stored procedure which gets
    called by the DAO in Websphere 5.1.
    The stored procedure takes couple of input array.
    Code snippet -
    CallableStatement cstmt = con.prepareCall("{call
    pkg_name.ap_name( ?,?,?,?,?,?,?,?,? )}");
    ArrayDescriptor desc =
    ArrayDescriptor.createDescriptor("STRING_VARRAY",
    con);
    ARRAY arr1 = new ARRAY(desc, con, strArray);
    cstmt.setArray(1, arr1);
    I get this exception when trying to create Oracle
    array desciptor -
    java.lang.ClassCastException:
    com/ibm/ws/rsadapter/jdbc/WSJdbcConnection
    incompatible with oracle/jdbc/OracleConnection
    How can I get a OracleJdbcConnection object from
    WSJdbcConnection?
    Is there any way to do this using the WS Jdbc
    classes?
    Is there any other way to pass an array to a callable
    statement?
    TIA.
    - vineetI am experiencing the same ClassCastException when creating an ArrayDescriptor. It occurs on execution the following line of code:-
    oracle.sql.ArrayDescriptorarrayDesc = oracle.sql.ArrayDescriptor.createDescriptor(schema + "." + table, conn);
    Java Context: Stateless EJB
    J2EE Version: 1.3
    JRE Version: 1.4.2
    EJB Version: 2.0
    J2EE Container: WebSphere v5.1.1.2, build number cf20446.02
    Container transaction type: Required (for all remote methods)
    Oracle Impl class: oracle.jdbc.xa.client.OracleXADataSource
    Oracle driver file: classes12.zip
    Oracle Version: 8.1.7.4
    Is there a solution to this issue?

  • Array concept in oracle

    I wanted to know if there is List/array concept in oracle like we have in C,C#.
    The reason behind asking this question is. I have a CSV files which has thousands of line of integers separated by comma. So let says the first file has the data that looks like -
    File1.txt -
    1,2,3,4
    5,6,8,9
    12,22,23,1,3
    I have another CSV file that has thousands of line of integers separated by comma which looks like.
    File2.txt
    5,6,7,8,9
    10,22,3,4,5
    What I was trying to achieve was to get the list of Int array which is present in File1.txt and not in File2.txt. Please note that the order of number in an array is not relevant. So, 1,2,3,4,5 is same as 4,5,3,2,1
    I tried to solve this with C# but it's taking too much time. So I wanted to explore if this is possible using oracle array/list concept.
    Please suggest

    >
    Sorry I did not included the full detail. So, for "4. Used a logic that excludes List2 from List1. " what I used was Linq query which looks like InputNumberList2.ForEach(x => InputNumberList1.RemoveAll(inner => inner.SequenceEqual(x))); ( I tried without using Linq too but no difference in time)
    >
    I'm not familiar with 'Linq' queries but from the description on this page (http://msdn.microsoft.com/en-us/library/bb397676.aspx) that appears to be doing a full iteration of the integer array for EVERY FILE2 ENTRY. That performance would be TERRIBLE. That is roughly equivalent to a cartesian join between two tables; something you almost never want to do.
    A hashmap.put and remove is very fast in comparison.
    >
    So, if I understood correctly, what you are suggesting is -
    1. First instead of int array , have a string array.
    2. use Hashtable or dictionary.
    >
    You have both. The int array holds the array of integers from the 'split' done on a record: '4,2,3,1' becomes an int array with 4 values.
    You sort the array and then create a string from it: Your input string is '4,2,3,1' and the new string would be '1,2,3,4' in order.
    You use the new string as the key to the hashmap and the record number the string came from as the value.
    When you add the new string (the HashMap 'put' method) the 'put' method returns 'null' if that string did not already exist but returns the previous value (the record number) if the string did exist.
    So if record #1 of file1 has the string '4,2,3,1' it will be stored in the map using myMap.put('1,2,3,4', 1) and that call will return NULL. Then if record #4 has the string '3,2,1,4' it will be stored in the map using myMap.put('1,2,3,4', 4) and that call will return '1' since that string already exists. You can now log that as a duplicate that exists in file1: the string you would log is '1,2,3,4' and the record number you log is '1'. By log I mean write to a file, put in a list/map, etc.
    That way you can always use your 'duplicate' list to find the original records in your input file by their record number.
    >
    Also I am not clear on this part - "And when your delete of a file2 string succeeds (meaning you had the same value in file2 as you had in file1) you can log THAT information to a 'file2_value_exists_in_file1' file with the record number of both the file1 and the file2 record."
    >
    The same concept applies here. For each file2 entry instead of myMap. put you use myMap.remove to try to remove the file2 string. The 'remove' method returns NULL if the string doesn't exist and returns the record number if the key DOES exist. So if the return value is NOT NULL then the returned record number is the record number in file1 that had that same string.
    You can save that file1 record number and string value in a list that represents file1 strings that also existed in file2. And you can save the file2 record number and string as the matching record from file2.

  • How to read an Oracle index by in Java

    Hi All,
    Could anyone help me, how can I use JDBC to read the contents of an Oracle index-by table. I am preparing this Oracle array in a procedure, which I need to send as an out parameter.
    A code segment will be highly appreciated.
    Thanx in advance.
    Regards,
    Dushyant

    I GOT IT!... I did not notice the "]" at the end. Crazy!!!!

  • Oracle.sql.STRUCT cannot be cast to oracle.sql.STRUCT

    I met a problem,I use oracle spatial to store geometry,then get it like this:
    STRUCT dbObject = (oracle.sql.STRUCT)rs.getObject("shape");
    JGeometry geom = JGeometry.load(dbObject);
    tomcat 6 told me java.lang.ClassCastException: oracle.sql.STRUCT cannot be cast to oracle.sql.STRUCT
    does everyone knows this problem?thanks
    Edited by: 811014 on 2010-11-13 下午9:28
    Edited by: 811014 on 2010-11-13 下午9:28

    Hi, this is a known problem for most Spatial 10g Java APIs with WLS.
    WLS is only certified with 11g DB.
    Instead of using Weblogic JNDI Lookup for Datasource, try the following snippet to create your connection/datasource (with Oracle JDBC thin driver):
    String databaseUrl = jdbc:oracle:thin:@1.2.3.4:1521:yourdbname
    String databaseUser = dbusername
    String databasePassword = dbpassword
    DriverManager.registerDriver(new OracleDriver());
    Connection aConnection = DriverManager.getConnection(databaseUrl, databaseUser, databasePassword);
    For more information, see the following:
    Classcast Exception while using Oracle ARRAYs
    regards,
    jack

  • Array of records registerOutParameter

    Hi !!
    I have a Pl/SQL function that returns an array of records. I want to call this procedure doing the following:
    st =conn.prepareCall("{? = call partes.PROYECTOS_DISPONIBLES(?,?,?)}");
    st.registerOutParameter(1, oracle.jdbc.driver.OracleTypes.ARRAY);
    but i don4t know how to cast the oracle array that return this function to i can access to this data.
    could anyone help me???
    Thanks in Advance

    I have the following:
    Type PROYECTO_REC
    AS OBJECT
    fat_pry_codig varchar2(10),
    fat_pry_pro_are_div_soc_codig number(3),
    fat_pry_pro_are_div_codig number(3),
    fat_pry_pro_are_codig number(3),
    fat_pry_pro_codig number(3),
    fat_pry_nrevi number(3),
    fat_codig varchar2(10),
    icate varchar2(1),
    cod varchar2(10),
    dproy varchar2(50),
    denom varchar2(50),
    drazas varchar2(100),
    horasl number,
    horasm number,
    horasx number,
    horasj number,
    horasv number,
    horass number,
    horasd number);
    and a table of it:
    type tabla_proy is table of proyecto_rec;
    and i have a function in pl/sql that returns a table of this type and i want from jdbc to have access to the tabla that return this function.
    Could anyone help me????

Maybe you are looking for