VARRAY INDEX

Hi,
i've following problem:
CREATE TYPE F_FLA_TYPE AS OBJECT (
ABC          VARCHAR2(3),
DEF VARCHAR2(7),
GHI VARCHAR2(14),
CREATE TYPE F_FLA_ARRAY AS VARRAY (999) OF F_FLA_TYPE
CREATE TABLE IFC (
ID NUMBER(12),
STATUS VARCHAR2(1),
FTA F_FLA_ARRAY,
VERSION NUMBER(3),
SOURCE VARCHAR2(100)
i want to create an index on IFC.FTA.ABC
how can i do this?
thanks for response.

I think you may not be able to create such an index on a named arrary type. Can you use a nested table instead, as shown below?
scott@ORA92> CREATE OR REPLACE TYPE f_fla_type AS OBJECT
  2    (abc VARCHAR2(3),
  3       def VARCHAR2(7),
  4       ghi VARCHAR2(15));
  5  /
Type created.
scott@ORA92> SHOW ERRORS
No errors.
scott@ORA92> CREATE OR REPLACE TYPE f_fla_array AS TABLE OF f_fla_type;
  2  /
Type created.
scott@ORA92> SHOW ERRORS
No errors.
scott@ORA92> CREATE TABLE ifc
  2    (id     NUMBER(12),
  3       status     VARCHAR2(1),
  4       fta     f_fla_array,
  5       version NUMBER(3),
  6       source     VARCHAR2(100))
  7    NESTED TABLE fta STORE AS fta_nestedtab
  8  /
Table created.
scott@ORA92> CREATE INDEX nested_tab_ix ON fta_nestedtab (abc)
  2  /
Index created.

Similar Messages

  • Constant declaration of VARRAY index by varchar2 within package header

    Hi there
    I'm looking for the correct syntax to declare a constant
    of a varray type which is indexed by varchar2. I've tried
    the following:
    create or replace package nl_types
    is
        TYPE nt_assoc_small IS TABLE OF INTEGER INDEX BY VARCHAR2(32);
        nl_bindcnt constant nt_assoc_small ('xml_gkregnl') := 3;
    end;
    I know this array hat just one element, but there will
    be even more when I got this example case to work. As
    I tried to compile this package, the compiler said:
    13/16 PL/SQL: Declaration ignored
    13/25 PLS-00566: type name "NT_ASSOC_SMALL" cannot be constrained
    13/70 PLS-00320: the declaration of the type of this expression is
    incomplete or malformed
    O.K. then: Does anybody know the "wellformed" declaration
    for this kind of varray?
    Thanx in advance,
    Martin.

    That's not a VARRAY declaration, it's a PL/SQL table / associative array.
    There is no syntax to declare the contents of an associative array in-line.
    They can either be assigned to directly or populated by BULK COLLECT (except for associative arrays indexed by VARCHAR2). Perhaps you could assign the return value of a function?
    Oracle Database 10g Enterprise Edition Release 10.1.0.2.0 - 64bit Production
    With the Partitioning, OLAP and Data Mining options
    SQL> CREATE OR REPLACE PACKAGE types AS
      2   
      3    TYPE associative_array_type IS TABLE OF INTEGER
      4      INDEX BY VARCHAR2 (32);
      5 
      6    FUNCTION default_associative_array_type
      7      RETURN associative_array_type;
      8    
      9  END;
    10  /
    Package created.
    SQL> CREATE OR REPLACE PACKAGE BODY types AS
      2 
      3    FUNCTION default_associative_array_type
      4      RETURN associative_array_type
      5    IS
      6      associative_array associative_array_type;
      7    BEGIN
      8      associative_array ('xml_gkregnl') := 3;
      9      RETURN associative_array;
    10    END;
    11    
    12  END;
    13  /
    Package body created.
    SQL> CREATE OR REPLACE PACKAGE constants AS
      2   
      3    associative_array CONSTANT types.associative_array_type :=
      4      types.default_associative_array_type;
      5     
      6  END;
      7  /
    Package created.
    SQL> SET SERVEROUTPUT ON;
    SQL> BEGIN
      2    DBMS_OUTPUT.PUT_LINE (
      3      'constants.associative_array (''xml_gkregnl'') => ' ||
      4        constants.associative_array ('xml_gkregnl'));
      5  END;
      6  /
    constants.associative_array ('xml_gkregnl') => 3
    PL/SQL procedure successfully completed.
    SQL>

  • Why do we need varrays ,index by table,pl/sql table etc when cursor is avai

    hi,
    Why do we need Composite data types like Index by Table, varrays etc when we have cursors and we can do all the things with cursor.
    Thanks
    Ram

    I would have to create a collection type for each column in the select statement.No.
    SQL> select count(*) from scott.emp ;
      COUNT(*)
            14
    1 row selected.
    SQL> DECLARE
      2      TYPE my_Table IS TABLE OF scott.emp%ROWTYPE;
      3      my_tbl my_Table;
      4  BEGIN
      5      SELECT * BULK COLLECT INTO my_tbl FROM scott.emp;
      6      dbms_output.put_line('Bulk Collect rows:'||my_tbl.COUNT) ;
      7  END;
      8  /
    Bulk Collect rows:14
    PL/SQL procedure successfully completed.
    SQL> disc
    Disconnected from Oracle9i Enterprise Edition Release 9.2.0.7.0 - Production
    With the Partitioning, OLAP and Oracle Data Mining options
    JServer Release 9.2.0.7.0 - Production
    SQL>Message was edited by:
    Kamal Kishore

  • Handling a List returned from a Stored Oracle Procedure

    I'm trying to put a PL/SQL oracle wrapper around some post code lookup
    software.
    We're planning to get the wrapper to return a List and then JDBC to handle this list.
    Has anyone already done/attempted to do this? Does anyone know if it can be done using a List and can oracle stored procedures return a List?

    It appears that Oracle does support an array type:
    In Oracle
    CREATE OR REPLACE FUNCTION getEmpArray RETURN EMPARRAY
    AS
    l_data EmpArray := EmpArray();
    CURSOR c_emp IS SELECT ename FROM EMP;
    BEGIN
    FOR emp_rec IN c_emp LOOP
    l_data.extend;
    l_data(l_data.count) := emp_rec.ename;
    END LOOP;
    RETURN l_data;
    END;
    In Java
    public static void main( ) {
      OracleCallableStatement stmt =(OracleCallableStatement)conn.prepareCall
                    ( "begin ? := getEMpArray; end;" );
        // The name we use below, EMPARRAY, has to match the name of the
        // type defined in the PL/SQL Stored Function
        stmt.registerOutParameter( 1, OracleTypes.ARRAY,"EMPARRAY" );
        stmt.executeUpdate();
        // Get the ARRAY object and print the meta data assosiated with it
        ARRAY simpleArray = stmt.getARRAY(1);
        System.out.println("Array is of type " +  simpleArray.getSQLTypeName());
        System.out.println("Array element is of type code "+simpleArray.getBaseType());
        System.out.println("Array is of length " + simpleArray.length());
        // Print the contents of the array
        String[] values = (String[])simpleArray.getArray();
        for( int i = 0; i < values.length; i++ )
          System.out.println( "row " + i + " = '" + values[i] +"'" );
    This was taken from:
    http://otn.oracle.com/sample_code/tech/java/codesnippet/jdbc/varray/index.html

  • Is possible to pass array/list as parameter in TopLink StoredProcedureCall?

    Hi, We need to pass an array/List/Vector of values (each value is a 10 character string) into TopLink's StoredProcedureCall. The maximum number of elements on the list is 3,000 (3,000 * 10 = 30,000 characters).
    This exposed two questions:
    1. Is it possible to pass a Vector as a parameter in TopLink's StoredProcedureCall, such as
    StoredProcedureCall call = new StoredProcedureCall();
    call.setProcedureName("STORED_PROCEDURE_NAME");
    call.addNamedArgument("PERSON_CODE");
    Vector strVect = new Vector(3000);
    strVect.add(“ab-gthhjko”);
    strVect.add(“cd-gthhjko”);
    strVect.add(“ef-gthhjko”);
    Vector parameters = new Vector();
    parameters.addElement(strVect);
    session.executeQuery(query,parameters);
    2. If the answer on previous question is yes:
    - How this parameter has to be defined in Oracle’s Stored Procedure?
    - What is the maximum number of elements/bytes that can be passed into the vector?
    The best way that we have found so far was to use single string as a parameter. The individual values would be delimited by comma, such as "ab-gthhjko,cd-gthhjko,ef-gthhjko..."
    However, in this case concern is the size that can be 3,000 * 11 = 33, 000 characters. The maximum size of VARCHAR2 is 4000, so we would need to break calls in chunks (max 9 chunks).
    Is there any other/more optimal way to do this?
    Thanks for your help!
    Zoran

    Hello,
    No, you cannot currently pass a vector of objects as a parameter to a stored procedure. JDBC will not take a vector as an argument unless you want it to serialize it (ie a blob) .
    The Oracle database though does have support for struct types and varray types. So you could define a stored procedure to take a VARRAY of strings/varchar, and use that stored procedure through TopLink. For instance:
    StoredProcedureCall call = new StoredProcedureCall();
    call.setProcedureName("STORED_PROCEDURE_NAME");
    call.addNamedArgument("PERSON_CODE");
    oracle.sql.ArrayDescriptor descriptor = new oracle.sql.ArrayDescriptor("ARRAYTYPE_NAME", dbconnection);
    oracle.sql.ARRAY dbarray = new oracle.sql.ARRAY(descriptor, dbconnection, dataArray);
    Vector parameters = new Vector();
    parameters.addElement(dbarray);
    session.executeQuery(query,parameters);This will work for any values as long as you are not going to pass in null as a value as the driver can determine the type from the object.
    dataArray is an Object array consisting of your String objects.
    For output or inoutput parameters you need to set the type and typename as well:
      sqlcall.addUnamedInOutputArgument("PERSON_CODE", "PERSON_CODE", Types.ARRAY, "ARRAYTYPE_NAME"); which will take a VARRAY and return a VARRAY type object.
    The next major release of TopLink will support taking in a vector of strings and performing the conversion to a VARRAY for you, as well as returning a vector instead of a VARRAY for out arguments.
    Check out thread
    Using VARRAYs as parameters to a Stored Procedure
    showing an example on how to get the conection to create the varray, as well as
    http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/varray/index.html on using Varrays in Oracle, though I'm sure the database docs might have more information.
    Best Regards,
    Chris

  • Help for function compile

    Please help me I don't know much about PLSQL FUNCTION
    I am getting fallowing error while compiling the function
    ine # = 3 Column # = 8 Error Text = PLS-00201: identifier 'MYVARCHARTABLE' must be declared
    where to declere and how to declere the MYVARCHARTABLE
    CREATE OR REPLACE FUNCTION "STR2TBL" ( p_str in
    varchar2)
    return myVarcharTable
    as
    l_str long default p_str || ',';
    l_n number;
    l_data myVarcharTable := myVarcharTable();
    begin
    loop
    l_n := instr( l_str, ',' );
    exit when (nvl(l_n,0) = 0);
    l_data.extend;
    l_data(l_data.count) := ( ltrim(rtrim(substr(l_str,1,l_n-1))) );
    l_str := ltrim( substr( l_str, l_n+1 ) );
    end loop;
    return l_data;
    end;

    Hi,
    This will give a clear idea about how to return an array from a PL/SQL Stored function.
    http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/varray/index.html
    Thanks,

  • ADF 11g : Calling PL Sql Function

    Hi there..
    I am trying to call a PL/SQL Function from my application module in ADF 11g.
    The code looks something like this
        public void getName(int relationNumber) {
            DBTransaction tc = getDBTransaction();
            StringBuffer statement = new StringBuffer("begin ");
            statement.append("? := COMP_RLE.RLE_GET_NAME(?);");
            statement.append("end;");
            OracleCallableStatement cs = (OracleCallableStatement)tc.createCallableStatement(statement.toString(), 0);
            try {
                cs.registerOutParameter(1, Types.VARCHAR);
                cs.setInt(2, relationNumber);
                cs.execute();
                String retValue = cs.getString(1);
                System.out.println(retValue);
            } catch (SQLException e) {
                System.err.println("Something went wrong: " + e.getMessage());
        }When I run this in TOAD I get a result back in the form of a String.
    However when I run the code above in a Unit Test I get back "null".
    Does anybody know what I am doing wrong here?
    Hope someone can help me out here.
    Thanks in advance,
    Gideon

    I think it will probably work that way.. but the thing is.. I have been going over examples.. and they work with the CallableStatement.
    I just want to know how come this isn't working the way it should.
    Did I miss something?
    Examples that I was looking at are:
    <li>http://www.experts-exchange.com/Programming/Languages/Java/Q_24106340.html
    <li>http://www.oracle.com/technology/sample_code/tech/java/codesnippet/jdbc/varray/index.html
    <li>Re: Returning a value from PL/SQL Function in ADF BC
    and
    <li>http://download.oracle.com/docs/cd/E15523_01/web.1111/b31974/bcadvgen.htm#sm0457
    They all work with the (Oracle)CallableStatement
    Edited by: Gideon Liem on Dec 4, 2009 12:27 AM

  • Q: 2-dim java Array to SQL rowtype?

    I wrote a piece of software that enables access from SQL to OpenCyc (the worlds largest common sense knowledge base). (see http://www.opencyc.org/ and http://217.117.225.187/~yeb/ooi.pdf and for the code http://cvs.sourceforge.net/cgi-bin/viewcvs.cgi/opencyc/oracle/ )
    It allows for queries like
    SELECT * FROM TABLE(
    SELECT cyc.askWithVariable( '(#$isa ?X #$Person)', '?X' ) FROM DUAL)
    It uses java to connect to opencyc. In the example above, askWithVariable returns an oracle.sql.ARRAY, that is constructed like this:
    ArrayDescriptor desc = ArrayDescriptor.createDescriptor("CYCLIST_TYPE", conn);
    oracle.sql.ARRAY arrayanswer = new oracle.sql.ARRAY(desc, conn, cyclist.toArray());
    The CYCLIST_TYPE is a TABLE OF VARCHAR(4000).
    The call specification maps this cyclist_type to oracle.sql.ARRAY, so it can be used in queries like the example above.
    Yesterday I've been trying (but not succeeding) to make a variant that returns a list of more than one variable; two dimensional array.
    Q1: Nowhere I've seen a multi column example of the select * from table( a collection ) construct. Is this possible at all?
    Q2: Is there a java example of a 2 dimensional array that gets converted to a PL/SQL or SQL type?
    Thanks!
    Yeb Havinga

    But when I was created stored procedure, array and customised data type with in package, java throws an exception like an invalid pattern You will have to create array type outside the package to make it work.
    Retruning array from plsql to java
    http://otn.oracle.com/sample_code/tech/java/codesnippet/jdbc/varray/index.html
    Writing array from java to plsql
    http://asktom.oracle.com/pls/ask/f?p=4950:8:385799930469889632::NO::F4950_P8_DISPLAYID,F4950_P8_CRITERIA:712625135727,
    Chandar

  • How to index a varray of object type?

    Hello,
    Is it possible to index a varray/Table type, which is of type of an object, like the way the scalar types are.
    say, CREATE OR REPLACE
    TYPE SAMPLE_TABLE AS TABLE OF Date index by binary_integer
    But if I have to change the table type from Date to an object
    lets say
    create or replace TYPE SAMPLE_TYPE AS OBJECT (
    id NUMBER(12),
    value varchar2(12)
    Will I be able to do
    CREATE OR REPLACE
    TYPE SAMPLE_TABLE AS TABLE OF SAMPLE_TYPE index by id
    If not, is there a way it can be done, or is it a limitaion that it cant be done. Any pointers to this is highly appreciated.
    Thanks

    One way to do this...
    SQL> drop type profile_options_object_array
      2  /
    SQL> drop type profile_options_object
      2  /
    SQL> drop table t
      2  /
    SQL>
    SQL> CREATE OR REPLACE TYPE profile_options_object AS OBJECT(
      2  option_name VARCHAR2(100),
      3  option_value VARCHAR(200)
      4  );
      5  /
    SQL> CREATE OR REPLACE TYPE profile_options_object_array AS VARRAY(32000) OF profile_options_object;
      2  /
    SQL>
    SQL> create table t
      2  (x varchar2(10)
      3  ,y varchar2(10)
      4  );
    SQL> insert into t values ('name1', 'value1');
    SQL> insert into t values ('name2', 'value2');
    SQL> commit;
    SQL>
    SQL> select profile_options_object (x, y)
      2    from t
      3  /
    PROFILE_OPTIONS_OBJECT(X,Y)(OPTION_NAME, OPTION_VALUE)
    PROFILE_OPTIONS_OBJECT('name1', 'value1')
    PROFILE_OPTIONS_OBJECT('name2', 'value2')
    SQL> declare
      2     profile_options  profile_options_object_array;
      3     idx pls_integer;
      4  begin
      5     select profile_options_object (x, y)
      6       bulk collect
      7       into profile_options
      8       from t
      9     ;
    10    idx := profile_options.first;
    11    while idx is not null
    12    loop
    13      dbms_output.put_line (profile_options(idx).option_name); 
    14      dbms_output.put_line (profile_options(idx).option_value);
    15      idx := profile_options.next(idx);
    16    end loop;
    17  end;
    18  /
    name1
    value1
    name2
    value2
    SQL>

  • Bug:4705928 PLSQL: Memory leak using small varrays

    We have Oracle version 10.2.0.1.0
    We have a problem with a procedure.
    In our scenario we make use of VARRAY in the procedure to pass some filter parameters to a select distinct querying a view made on three tables.
    Unfotunately not always execution it is successful.
    Sometimes it returns wrong value (0 for the count parameter), sometimes (rarely) the server stops working.
    We suspect that this is caused by a bug fixed in versione 10.2.0.3.0
    Bug:4705928 PLSQL: Memory leak using small varrays when trimming the whole collection and inserting into it in a loop
    We suspect this becasue we made two procedure the first (spProductCount) uses a function (fnProductFilter) to calculate the values of a varray and passes them into the select,
    while in the second procedure (spProductCount2) parameters are passed directly into the statement without varray
    and there are failures only in the first procedure.
    On the other hand on another server 10.2.0.1.0 we never have this problem.
    The instance manifesting the bug runs under shared mode, while the other is under dedicated mode.
    Turning the first one to dedicated mode makes the bugs disapear.
    Unfortunately this is not a solution.
    In the sample there are the three table with all constraints, the view, tha varray custom type, the function and the two procedures.
    Is there someone that may examine our sample and tell us if the pl/sql code corresponds to the bug desciption.
    We also want to know if it's possibile that the same server running under different mode (SHARED/DEDICATED) doesn't behave the same way.
    The tables:
    --Products
    CREATE TABLE "Products" (
         "Image" BLOB
         , "CatalogId" RAW(16)
         , "ProductId" RAW(16)
         , "MnemonicId" NVARCHAR2(50) DEFAULT ''
         , "ProductParentId" RAW(16)
    ALTER TABLE "Products"
         ADD CONSTRAINT "NN_Products_M04" CHECK ("CatalogId" IS NOT NULL)
    ALTER TABLE "Products"
         ADD CONSTRAINT "NN_Products_M05" CHECK ("ProductId" IS NOT NULL)
    ALTER TABLE "Products"
    ADD CONSTRAINT "PK_Products"
    PRIMARY KEY ("ProductId")
    CREATE INDEX "IX_Products"
    ON "Products" ("CatalogId", "MnemonicId")
    CREATE UNIQUE INDEX "UK_Products"
    ON "Products" (DECODE("MnemonicId", NULL, NULL, RAWTOHEX("CatalogId") || "MnemonicId"))
    --Languages
    CREATE TABLE "Languages" (
         "Description" NVARCHAR2(250)
         , "IsStandard" NUMBER(1)
         , "LanguageId" RAW(16)
         , "MnemonicId" NVARCHAR2(12)
    ALTER TABLE "Languages"
         ADD CONSTRAINT "NN_Languages_M01" CHECK ("LanguageId" IS NOT NULL)
    ALTER TABLE "Languages"
         ADD CONSTRAINT "NN_Languages_M05" CHECK ("MnemonicId" IS NOT NULL)
    ALTER TABLE "Languages"
    ADD CONSTRAINT "PK_Languages"
    PRIMARY KEY ("LanguageId")
    ALTER TABLE "Languages"
    ADD CONSTRAINT "UK_Languages"
    UNIQUE ("MnemonicId")
    --ProductDesc
    CREATE TABLE "ProductDesc" (
         "Comment" NCLOB
         , "PlainComment" NCLOB
         , "Description" NVARCHAR2(250)
         , "DescriptionText" NCLOB
         , "PlainDescriptionText" NCLOB
         , "LanguageId" NVARCHAR2(12)
         , "ProductId" RAW(16)
    ALTER TABLE "ProductDesc"
         ADD CONSTRAINT "NN_ProductDescM01" CHECK ("LanguageId" IS NOT NULL)
    ALTER TABLE "ProductDesc"
         ADD CONSTRAINT "NN_ProductDescM02" CHECK ("ProductId" IS NOT NULL)
    ALTER TABLE "ProductDesc"
    ADD CONSTRAINT "PK_ProductDesc"
    PRIMARY KEY ("ProductId", "LanguageId")
    ALTER TABLE "ProductDesc"
    ADD CONSTRAINT "FK_ProductDesc1"
    FOREIGN KEY("ProductId") REFERENCES "Products" ("ProductId")
    ALTER TABLE "ProductDesc"
    ADD CONSTRAINT "FK_ProductDesc2"
    FOREIGN KEY("LanguageId") REFERENCES "Languages" ("MnemonicId")
    /The view:
    --ProductView
    CREATE OR REPLACE VIEW "vwProducts"
    AS
         SELECT
               "Products"."CatalogId"
              , "ProductDesc"."Comment"
              , "ProductDesc"."PlainComment"
              , "ProductDesc"."Description"
              , "ProductDesc"."DescriptionText"
              , "ProductDesc"."PlainDescriptionText"
              , "Products"."Image"
              , "Languages"."MnemonicId" "LanguageId"
              , "Products"."MnemonicId"
              , "Products"."ProductId"
              , "Products"."ProductParentId"
              , TRIM(NVL("ProductDesc"."Description" || ' ', '') || NVL("ParentDescriptions"."Description", '')) "FullDescription"
         FROM "Products"
         CROSS JOIN "Languages"
         LEFT OUTER JOIN "ProductDesc"
         ON "Products"."ProductId" = "ProductDesc"."ProductId"
         AND "ProductDesc"."LanguageId" = "Languages"."MnemonicId"
         LEFT OUTER JOIN "ProductDesc" "ParentDescriptions"
         ON "Products"."ProductParentId" = "ParentDescriptions"."ProductId"
         AND ("ParentDescriptions"."LanguageId" = "Languages"."MnemonicId")
    /The varray:
    --CustomType VARRAY
    CREATE OR REPLACE TYPE Varray_Params IS VARRAY(100) OF NVARCHAR2(1000);
    /The function:
    --FilterFunction
    CREATE OR REPLACE FUNCTION "fnProductFilter" (
         parCatalogId "Products"."CatalogId"%TYPE,
         parLanguageId                    NVARCHAR2 := N'it-IT',
         parFilterValues                    OUT Varray_Params
    RETURN INTEGER
    AS
         varSqlCondition                    VARCHAR2(32000);
         varSqlConditionValues          NVARCHAR2(32000);
         varSql                              NVARCHAR2(32000);
         varDbmsCursor                    INTEGER;
         varDbmsResult                    INTEGER;
         varSeparator                    VARCHAR2(2);
         varFilterValue                    NVARCHAR2(1000);
         varCount                         INTEGER;
    BEGIN
         varSqlCondition := '(T_Product."CatalogId" = HEXTORAW(:parentId)) AND (T_Product."LanguageId" = :languageId )';
         varSqlConditionValues := CHR(39) || TO_CHAR(parCatalogId) || CHR(39) || N', ' || CHR(39 USING NCHAR_CS) || parLanguageId || CHR(39 USING NCHAR_CS);
         parFilterValues := Varray_Params();
         varSql := N'SELECT FilterValues.column_value FilterValue FROM TABLE(Varray_Params(' || varSqlConditionValues || N')) FilterValues';
         BEGIN
              varDbmsCursor := dbms_sql.open_cursor;
              dbms_sql.parse(varDbmsCursor, varSql, dbms_sql.native);
              dbms_sql.define_column(varDbmsCursor, 1, varFilterValue, 1000);
              varDbmsResult := dbms_sql.execute(varDbmsCursor);
              varCount := 0;
              LOOP
                   IF (dbms_sql.fetch_rows(varDbmsCursor) > 0) THEN
                        varCount := varCount + 1;
                        dbms_sql.column_value(varDbmsCursor, 1, varFilterValue);
                        parFilterValues.extend(1);
                        parFilterValues(varCount) := varFilterValue;
                   ELSE
                        -- No more rows to copy
                        EXIT;
                   END IF;
              END LOOP;
              dbms_sql.close_cursor(varDbmsCursor);
         EXCEPTION WHEN OTHERS THEN
              dbms_sql.close_cursor(varDbmsCursor);
              RETURN 0;
         END;
         FOR i in parFilterValues.first .. parFilterValues.last LOOP
              varSeparator := ', ';
         END LOOP;
         RETURN 1;
    END;
    /The procedures:
    --Procedure presenting anomaly\bug
    CREATE OR REPLACE PROCEDURE "spProductCount" (
         parCatalogId "Products"."CatalogId"%TYPE,
         parLanguageId NVARCHAR2 := N'it-IT',
         parRecords OUT NUMBER
    AS
         varFilterValues Varray_Params;
         varResult INTEGER;
         varSqlTotal VARCHAR2(32000);
    BEGIN
         parRecords := 0;
         varResult := "fnProductFilter"(parCatalogId, parLanguageId, varFilterValues);
         varSqlTotal := 'BEGIN
         SELECT count(DISTINCT T_Product."ProductId") INTO :parCount FROM "vwProducts" T_Product
              WHERE ((T_Product."CatalogId" = HEXTORAW(:parentId)) AND (T_Product."LanguageId" = :languageId ));
    END;';
         EXECUTE IMMEDIATE varSqlTotal USING OUT parRecords, varFilterValues(1), varFilterValues(2);
    END;
    --Procedure NOT presenting anomaly\bug
    CREATE OR REPLACE PROCEDURE "spProductCount2" (
         parCatalogId "Products"."CatalogId"%TYPE,
         parLanguageId NVARCHAR2 := N'it-IT',
         parRecords OUT NUMBER
    AS
         varFilterValues Varray_Params;
         varResult INTEGER;
         varSqlTotal VARCHAR2(32000);
    BEGIN
         parRecords := 0;
         varSqlTotal := 'BEGIN
         SELECT count(DISTINCT T_Product."ProductId") INTO :parCount FROM "vwProducts" T_Product
              WHERE ((T_Product."CatalogId" = HEXTORAW(:parentId)) AND (T_Product."LanguageId" = :languageId ));
    END;';
         EXECUTE IMMEDIATE varSqlTotal USING OUT parRecords, parCatalogId, parLanguageId;
    END;Edited by: 835125 on 2011-2-9 1:31

    835125 wrote:
    Using VARRAY was the only way I found to transform comma seprated text values (e.g. "'abc', 'def', '123'") in a collection of strings.A varray is just a functionally crippled version of a nested table collection type, with a defined limit you probably don't need. (Why 100 specifically?) Instead of
    CREATE OR REPLACE TYPE varray_params AS VARRAY(100) OF NVARCHAR2(1000);try
    CREATE OR REPLACE TYPE array_params AS TABLE OF NVARCHAR2(1000);I don't know whether that will solve the problem but at least it'll be a slightly more useful type.
    What makes you think it's a memory leak specifically? Do you observe session PGA memory use going up more than it should?
    btw good luck with all those quoted column names. I wouldn't like to have to work with those, although they do make the forum more colourful.
    Edited by: William Robertson on Feb 11, 2011 7:54 AM

  • Creating and displaying Varrays in Apex 4.1

    Hi,
    I am creating quite a sophisticated database, which has to support relations between different tables. In order to implement that, I've decided to use user-defined datatype - a varray which consists of 100 integers (and only of that) that will contain ID's to different rows in different tables. Since it is a user-defined datatype I have problems with using it in Application Express :)
    First question: Is there any way to make this simple datatype 'readable' for Apex? In each application I create it shows that it is 'an unsupported datatype'. Maybe I should define something more than just varray construction - the way Apex should read and edit it etc ?
    Second question: How can I implement a function that will read the IDs in the varray and transform them into names to which that IDs correspond? I would like an application to show full name of an organization (ex. "ABC Corporation") instead of its ID. I tried to put some part of code that takes up the name of an organisation in a row with given ID into +"Source"+ form in the +"Edit page item"+, however Apex doesn't seem to get the fact that the data is in different table. Any ideas? :)
    I will be grateful for any help since it is an urgent case :]

    KamilGorski wrote:
    I would happily do that if only I had more time to study SQL and learn it properly :) Unfortunately, our start-up company has no time and money at the moment to allow me to do so.Then isn't using technologies that no one knows rather a strange decision?
    But coming back to your solution - it still works only if user inputs only one product quality. Let's say that user has chosen 3 qualities and the 'SELECTED_QUALITIES' collection looks like that:
    n001 = 1,
    n002 = 3,
    n003 = 5
    And since the SELECT query you have created compares pq.quality_id only to n001, it returns all the products that have the quality no 1 - not all the products that have all three selected qualities - 1, 3 and 5. Of course, we can change the 'EXISTS' condition and add more 'OR' conditions like that:
    where pq.quality_id = q.n001
    or pq.quality_id = q.n002
    or pq.quality_id = q.n003But it has few flaws - first we assume that we know the number of qualities user has selected - 3 (and we don't know that), You've misunderstood. SQL is row based. To handle multiple values, we create more rows, not additional columns. In your preferred terms, the result of any query is an <i>m</i>&times;<i>n</i> array of columns and rows, where the number of columns <i>m</i> is fixed, and the number of rows <i>n</i> varies according to the query predicates.
    It is not necessary to know the number of selected qualities, simply create a row in the collection for each selected quality to give a set of selected qualities.
    The SELECTED_QUALITIES collection should look like:
    N001
       1
       3
       5
    secondly the query will return all the products that have one of the three selected qualities (and we want products that have all three qualities). That wasn't really clear from the information previously given, but it's certainly possible. With <tt>product_qualities(product_id, quality_id)</tt> as a primary/unique key, and with no duplicates in the selected qualities, a solution is the set of all products with the selected qualities, where the number of qualities matched for each product equals the number of qualities selected, as in this example:
    SQL> create table products (
      2      product_id    integer       primary key
      3    , product_name  varchar2(30)  not null);
    Table created.
    SQL> create table qualities (
      2      quality_id    integer       primary key
      3    , quality_name  varchar2(30)  not null);
    Table created.
    SQL> create table product_qualities (
      2        product_id  integer   not null references products
      3      , quality_id  integer   not null references qualities,
      4      constraint product_qualities_pk primary key (
      5            product_id
      6          , quality_id))
      7    organization index;
    Table created.
    SQL> create index product_qualities_ix2 on product_qualities (
      2      quality_id
      3    , product_id);
    Index created.
    SQL> insert all
      2    into products (product_id, product_name) values (1, 'widget')
      3    into products (product_id, product_name) values (2, 'thingummy')
      4    into products (product_id, product_name) values (3, 'whatsit')
      5    into products (product_id, product_name) values (4, 'gizmo')
      6    into products (product_id, product_name) values (5, 'gadget')
      7    into products (product_id, product_name) values (6, 'contraption')
      8  select * from dual;
    6 rows created.
    SQL> insert all
      2    into qualities (quality_id, quality_name) values (1, 'green')
      3    into qualities (quality_id, quality_name) values (2, 'silver')
      4    into qualities (quality_id, quality_name) values (3, 'shiny')
      5    into qualities (quality_id, quality_name) values (4, 'furry')
      6    into qualities (quality_id, quality_name) values (5, 'digital')
      7    into qualities (quality_id, quality_name) values (6, 'hd')
      8    into qualities (quality_id, quality_name) values (7, 'wireless')
      9  select * from dual;
    7 rows created.
    SQL> insert all
      2    into product_qualities (product_id, quality_id) values (1, 1)
      3    into product_qualities (product_id, quality_id) values (1, 3)
      4    into product_qualities (product_id, quality_id) values (2, 2)
      5    into product_qualities (product_id, quality_id) values (2, 4)
      6    into product_qualities (product_id, quality_id) values (3, 1)
      7    into product_qualities (product_id, quality_id) values (3, 3)
      8    into product_qualities (product_id, quality_id) values (3, 5)
      9    into product_qualities (product_id, quality_id) values (4, 2)
    10    into product_qualities (product_id, quality_id) values (4, 4)
    11    into product_qualities (product_id, quality_id) values (4, 6)
    12    into product_qualities (product_id, quality_id) values (5, 2)
    13    into product_qualities (product_id, quality_id) values (5, 3)
    14    into product_qualities (product_id, quality_id) values (5, 5)
    15    into product_qualities (product_id, quality_id) values (6, 1)
    16    into product_qualities (product_id, quality_id) values (6, 3)
    17    into product_qualities (product_id, quality_id) values (6, 5)
    18    into product_qualities (product_id, quality_id) values (6, 7)
    19  select * from dual;
    17 rows created.
    SQL> commit;
    Commit complete.For the purposes of creating a quick and simple example outside of APEX, I'm using a temporary table instead of the SELECTED_QUALITIES APEX collection. For various reasons collections work better in APEX than GTTs and are the preferred approach for temporary storage.
    SQL> create global temporary table selected_qualities (
      2    n001 integer)
      3  on commit delete rows;
    Table created.With one quality selected, we get all the products having that quality:
    SQL> insert into selected_qualities (n001) values (1);
    1 row created.
    SQL> insert into selected_qualities (n001) values (1);
    1 row created.
    SQL> select
      2            p.product_id
      3          , p.product_name
      4  from
      5            products p
      6           join product_qualities pq
      7             on p.product_id = pq.product_id
      8           join selected_qualities sq
      9             on pq.quality_id = sq.n001
    10  group by
    11            p.product_id
    12          , p.product_name
    13  having
    14             count(*) = (select count(*) from selected_qualities);
    PRODUCT_ID PRODUCT_NAME
          1 widget
          6 contraption
          3 whatsitThese products all have the next quality added, so continue to be returned:
    SQL> insert into selected_qualities (n001) values (3);
    1 row created.
    SQL> select
      2            p.product_id
      3          , p.product_name
      4  from
      5            products p
      6           join product_qualities pq
      7             on p.product_id = pq.product_id
      8           join selected_qualities sq
      9             on pq.quality_id = sq.n001
    10  group by
    11            p.product_id
    12          , p.product_name
    13  having
    14             count(*) = (select count(*) from selected_qualities);
    PRODUCT_ID PRODUCT_NAME
          1 widget
          6 contraption
          3 whatsitThen as additional qualities are selected, the result set is progressively reduced:
    SQL> insert into selected_qualities (n001) values (5);
    1 row created.
    SQL> select
      2            p.product_id
      3          , p.product_name
      4  from
      5            products p
      6           join product_qualities pq
      7             on p.product_id = pq.product_id
      8           join selected_qualities sq
      9             on pq.quality_id = sq.n001
    10  group by
    11            p.product_id
    12          , p.product_name
    13  having
    14             count(*) = (select count(*) from selected_qualities);
    PRODUCT_ID PRODUCT_NAME
          6 contraption
          3 whatsit
    SQL> insert into selected_qualities (n001) values (7);
    1 row created.
    SQL> select
      2            p.product_id
      3          , p.product_name
      4  from
      5            products p
      6           join product_qualities pq
      7             on p.product_id = pq.product_id
      8           join selected_qualities sq
      9             on pq.quality_id = sq.n001
    10  group by
    11            p.product_id
    12          , p.product_name
    13  having
    14             count(*) = (select count(*) from selected_qualities);
    PRODUCT_ID PRODUCT_NAME
          6 contraption

  • Partitioned IOT of Object Type - mapping table not allowed for bitmap index

    Hi,
    looks like a feature available for standard Partitioned IOTs is not supported for object based tables, namely the MAPPING TABLE construct to support secondary local bitmap indexes.
    Can you confirm behaviour is as expected/documented?
    If so, is a fix/enhancement to support mapping table for object-based Partitioned IOTs in the pipeline?
    Results for partition-wise load using pipelined table function are very good, look-ups across tens of millions of rows are excellent.
    Environment = Oracle Database 11g Enterprise Edition Release 11.2.0.1.0 - Production
    OS = Oracle Enterprise Linux Server release 5.2 (Carthage) 2.6.18 92.el5 (32-bit)
    Here's the potted test-case...
    1) First the non object based Partitioned IOT - data is range-partitioned across the alphabet
    CREATE TABLE IOT_Table (
    textData VARCHAR2(10),
    numberData NUMBER(10,0),
    CONSTRAINT IOT_Table_PK PRIMARY KEY(textData))
    ORGANIZATION INDEX MAPPING TABLE PCTFREE 0 TABLESPACE Firewire
    PARTITION BY RANGE (textData)
    (PARTITION Text_Part_A VALUES LESS THAN ('B') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_B VALUES LESS THAN ('C') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_C VALUES LESS THAN ('D') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_D VALUES LESS THAN ('E') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_E VALUES LESS THAN ('F') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_F VALUES LESS THAN ('G') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_G VALUES LESS THAN ('H') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_H VALUES LESS THAN ('I') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_I VALUES LESS THAN ('J') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_J VALUES LESS THAN ('K') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_K VALUES LESS THAN ('L') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_L VALUES LESS THAN ('M') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_M VALUES LESS THAN ('N') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_N VALUES LESS THAN ('O') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_O VALUES LESS THAN ('P') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_P VALUES LESS THAN ('Q') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_Q VALUES LESS THAN ('R') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_R VALUES LESS THAN ('S') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_S VALUES LESS THAN ('T') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_T VALUES LESS THAN ('U') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_U VALUES LESS THAN ('V') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_V VALUES LESS THAN ('W') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_W VALUES LESS THAN ('X') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_X VALUES LESS THAN ('Y') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_Y VALUES LESS THAN ('Z') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_Z VALUES LESS THAN (MAXVALUE) PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0))
    NOLOGGING PARALLEL -- FLASHBACK ARCHIVE IOT_Flashback_Data
    SQL> table IOT_TABLE created.
    2) Create the local secondary bitmap index utilising the underlying mapping table
    CREATE BITMAP INDEX IOT_Table_BMI1 ON IOT_Table (numberData)
    LOCAL STORAGE (INITIAL 1M PCTINCREASE 0 NEXT 512K) NOLOGGING PARALLEL;
    SQL> bitmap index IOT_TABLE_BMI1 created.
    3) Quick test to confirm all ok
    SQL> INSERT INTO IOT_Table VALUES ('ABC123',100);
    SQL> 1 rows inserted.
    SQL> SELECT * FROM IOT_Table;
    TEXTDATA NUMBERDATA
    ABC123     100
    4) Now create a minimal object type to use as the template for object table
    CREATE TYPE IOT_type AS OBJECT
    textData VARCHAR2(10 CHAR),
    numberData NUMBER(10,0)
    ) FINAL
    SQL> TYPE IOT_type compiled
    5) Attempt to create an object-based range partitioned IOT, including MAPPING TABLE clause as per step (1)
    CREATE TABLE IOTObj_Table OF IOT_type (textData PRIMARY KEY)
    OBJECT IDENTIFIER IS PRIMARY KEY ORGANIZATION INDEX
    MAPPING TABLE -- we'd like to use this feature to enable use of Bitmap Indexes...
    PCTFREE 0 TABLESPACE Firewire
    PARTITION BY RANGE (textData)
    (PARTITION Text_Part_A VALUES LESS THAN ('B') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_B VALUES LESS THAN ('C') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_C VALUES LESS THAN ('D') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_D VALUES LESS THAN ('E') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_E VALUES LESS THAN ('F') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_F VALUES LESS THAN ('G') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_G VALUES LESS THAN ('H') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_H VALUES LESS THAN ('I') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_I VALUES LESS THAN ('J') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_J VALUES LESS THAN ('K') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_K VALUES LESS THAN ('L') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_L VALUES LESS THAN ('M') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_M VALUES LESS THAN ('N') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_N VALUES LESS THAN ('O') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_O VALUES LESS THAN ('P') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_P VALUES LESS THAN ('Q') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_Q VALUES LESS THAN ('R') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_R VALUES LESS THAN ('S') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_S VALUES LESS THAN ('T') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_T VALUES LESS THAN ('U') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_U VALUES LESS THAN ('V') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_V VALUES LESS THAN ('W') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_W VALUES LESS THAN ('X') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_X VALUES LESS THAN ('Y') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_Y VALUES LESS THAN ('Z') PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0),
    PARTITION Text_Part_Z VALUES LESS THAN (MAXVALUE) PCTFREE 0 TABLESPACE Firewire Storage (Initial 10M Next 1M PCTIncrease 0))
    NOLOGGING PARALLEL -- FLASHBACK ARCHIVE IOT_Flashback_Data
    This errors out with the following...
    SQL Error: ORA-25182: feature not currently available for index-organized tables
    25182. 00000 - "feature not currently available for index-organized tables"
    *Cause:    An attempt was made to use one or more of the following feature(s) not
    currently supported for index-organized tables:
    CREATE TABLE with LOB/BFILE/VARRAY columns,
    partitioning/PARALLEL/CREATE TABLE AS SELECT options,
    ALTER TABLE with ADD/MODIFY column options, CREATE INDEX
    *Action:   Do not use the disallowed feature(s) in this release.
    6) Re-running the create table statement in step 5 without the MAPPING TABLE clause works fine. Not surprisingly an attempt to create a secondary local bitmap index on this table fails as there's no mapping table, like so...
    CREATE BITMAP INDEX IOTObj_Table_BMI1 ON IOTObj_Table (numberData)
    LOCAL STORAGE (INITIAL 1M PCTINCREASE 0 NEXT 512K) NOLOGGING PARALLEL;
    CREATE TABLE with LOB/BFILE/VARRAY columns,
    partitioning/PARALLEL/CREATE TABLE AS SELECT options,
    ALTER TABLE with ADD/MODIFY column options, CREATE INDEX
    *Action:   Do not use the disallowed feature(s) in this release.
    CREATE BITMAP INDEX IOTObj_Table_BMI1 ON IOTObj_Table (numberData)
    LOCAL STORAGE (INITIAL 1M PCTINCREASE 0 NEXT 512K) NOLOGGING PARALLEL
    Error at Command Line:99 Column:13
    Error report:
    SQL Error: ORA-00903: invalid table name
    00903. 00000 - "invalid table name"
    7) Creating a secondary local b-tree index is fine, like so...
    SQL> CREATE INDEX IOTObj_Table_I1 ON IOTObj_Table (numberData)
    LOCAL STORAGE (INITIAL 1M PCTINCREASE 0 NEXT 512K) NOLOGGING PARALLEL;
    index IOTOBJ_TABLE_I1 created.
    8) A quick test to ensure object table ok...
    SQL> INSERT INTO IOTObj_Table VALUES (IOT_Type('DEF456',500));
    SQL> 1 rows inserted.
    SQL> SELECT * FROM IOTObj_Table;
    TEXTDATA NUMBERDATA
    DEF456     500

    Thanks Dan,
    the intention is to range partition based on the initial character, so A* -> Text_Part_A, B* -> Text_Part_B, and so on.
    Here's an example, using an empty IOTObj_Table as created previously.
    1) Set up & confirm some test data (two 'D's, one 'N', and two 'Z's)
    SQL> INSERT INTO IOTObj_Table VALUES (IOT_Type('DEF456',500));
    SQL> INSERT INTO IOTObj_Table VALUES (IOT_Type('DDD111',510));
    SQL> INSERT INTO IOTObj_Table VALUES (IOT_Type('N3000',515));
    SQL> INSERT INTO IOTObj_Table VALUES (IOT_Type('ZZ1212',520));
    SQL> INSERT INTO IOTObj_Table VALUES (IOT_Type('Z111X',530));
    SQL> COMMIT;
    SQL> SELECT * FROM IOTObj_Table;
    TEXTDATA NUMBERDATA
    DDD111     510
    DEF456     500
    N3000     515
    Z111X     530
    ZZ1212     520
    2) Just to prove our IOT is enforcing the Primary Key based on the TextData attribute, try to insert a duplicate
    SQL> INSERT INTO IOTObj_Table VALUES (IOT_Type('Z111X',530));
    Error starting at line 141 in command:
    INSERT INTO IOTObj_Table VALUES (IOT_Type('Z111X',530))
    Error report:
    SQL Error: ORA-00001: unique constraint (OCDataSystems.SYS_IOT_TOP_84235) violated
    00001. 00000 - "unique constraint (%s.%s) violated"
    *Cause:    An UPDATE or INSERT statement attempted to insert a duplicate key.
    For Trusted Oracle configured in DBMS MAC mode, you may see
    this message if a duplicate entry exists at a different level.
    *Action:   Either remove the unique restriction or do not insert the key.
    3) Now confirm that our data has been slotted into the range-based partition we expect using the PARTITION clause of SELECT...
    - The two 'D's...
    SQL> SELECT * FROM IOTObj_Table PARTITION (Text_Part_D);
    TEXTDATA NUMBERDATA
    DDD111     510
    DEF456     500
    - The single 'N'...
    SQL> SELECT * FROM IOTObj_Table PARTITION (Text_Part_N);
    TEXTDATA NUMBERDATA
    N3000     515
    - The two 'Z's...
    SQL> SELECT * FROM IOTObj_Table PARTITION (Text_Part_Z);
    TEXTDATA NUMBERDATA
    Z111X     530
    ZZ1212     520
    4) And to wrap up confirm an empty partition
    SELECT * FROM IOTObj_Table PARTITION (Text_Part_W);

  • VARRAY colletion type retirval from java , Wrong data ???? retrieved.

    Hi all,
    I am trying to retirve VARRAY collection type created in oracle from Java. It gives the wrong results as below:
    ********Fetch Starts....********
    ********Row 1 :
    Array is of type MY_UID.STRING_VARRAY
    Array is of length 2
    index 0 = ???
    index 1 = ???
    ********Fetch Ends....********
    Note: I nls_charcterset12.jar, classes12.jar are included in project class path.
    After breaking my head for two decided to request for help from big brains out there.
    For understanding, the code is attached and any help would be appriciated on this regard.
    Advance Thanks,
    Venkat
    The Code:
    import java.sql.*;
    import oracle.sql.*;
    import oracle.jdbc.oracore.Util;
    import oracle.jdbc.*;
    public class VArrayManipulation
    public static void main (String args[])
    throws Exception
    // DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
    // The sample retrieves an varray of type "STRING_VARRAY",
    // materializes the object as an object of type ARRAY.
    // A new ARRAY is then inserted into the database.
    // String url = "<connection url>";
    // Connect to the database
    Connection conn =null;
    // DriverManager.getConnection (url, "<user>" , "<password>");
    DriverManager.registerDriver(new oracle.jdbc.driver.OracleDriver());
    conn = DriverManager.getConnection(
    "jdbc:oracle:thin:@localhost:1521:system", "my_uid","my_password");
    conn.setAutoCommit (false);
    // Create a Statement
    Statement stmt = conn.createStatement ();
    try
    stmt.execute ("DROP TABLE sample_varray_table");
    stmt.execute ("DROP TYPE string_varray");
    catch (SQLException e)
    //Exceptions will be thrown if Table and types doesnt exist . Ignore this
    stmt.execute ("CREATE TYPE string_varray AS VARRAY(10) OF VARCHAR2(100)");
    stmt.execute ("CREATE TABLE sample_varray_table (acol string_varray)");
    //Insert using SQL
    stmt.execute ("INSERT INTO sample_varray_table VALUES (string_varray('Test1', 'Test2'))");
    ResultSet rs = stmt.executeQuery("SELECT acol FROM sample_varray_table");
    printResultSet (rs);
    //Insert using ArrayDescriptor
    // create a new ARRAY object
    String arrayElements[] = { "Test3", "Test4" };
    ArrayDescriptor desc = ArrayDescriptor.createDescriptor
    ("STRING_VARRAY", conn);
    ARRAY newArray = new ARRAY(desc, conn, arrayElements);
    PreparedStatement ps =
    conn.prepareStatement ("insert into sample_varray_table values (?)");
    ((OraclePreparedStatement)ps).setARRAY (1, newArray);
    ps.execute ();
    rs = stmt.executeQuery("SELECT acol FROM sample_varray_table");
    printResultSet (rs);
    // Close all the resources
    rs.close();
    ps.close();
    stmt.close();
    conn.close();
    public static void printResultSet (ResultSet rs)
    throws SQLException
    System.out.println("********Fetch Starts....********");
    int line = 0;
    while (rs.next())
    line++;
    System.out.println("********Row "+line+" : ");
    ARRAY array = ((OracleResultSet)rs).getARRAY (1);
    System.out.println ("Array is of type "+array.getSQLTypeName());
    System.out.println ("Array is of length "+array.length());
    // get Array elements
    String[] values = (String[]) array.getArray();
    for (int i=0; i<values.length; i++)
    System.out.println("index "+i+" = "+values[i] );
    System.out.println("********Fetch Ends....********");
    }

    import java.sql.Array;
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.Statement;
    import oracle.sql.ARRAY;
    import oracle.sql.ArrayDescriptor;
    public class test
        public static void main (String args[]) throws Exception
            DriverManager.registerDriver(new oracle.jdbc.OracleDriver());
            Connection conn = DriverManager.getConnection
                ("jdbc:oracle:thin:@sta00077.us.oracle.com:1521:xe", "scott","tiger");
            Statement stmt = conn.createStatement ();
            try {
                stmt.execute("DROP TABLE varray_table");
                stmt.execute("DROP TYPE string_varray");
            } catch (Exception e) { }
            stmt.execute("CREATE TYPE string_varray AS VARRAY(10) OF VARCHAR2(10)");
            stmt.execute("CREATE TABLE varray_table (sv string_varray)");
            stmt.execute("INSERT INTO varray_table VALUES (string_varray('Test1', 'Test2'))");
            ResultSet rs = stmt.executeQuery("SELECT sv FROM varray_table");
            printResultSet(rs);
            String arrayElements[] = { "Test3", "Test4", "Test5" };
            ArrayDescriptor desc = ArrayDescriptor.createDescriptor("STRING_VARRAY", conn);
            ARRAY newArray = new ARRAY(desc, conn, arrayElements);
            PreparedStatement ps = conn.prepareStatement("INSERT INTO varray_table VALUES (?)");
            ps.setArray(1, (Array)newArray);
            ps.execute();
            rs = stmt.executeQuery("SELECT sv FROM varray_table");
            printResultSet(rs);
            rs.close();
            ps.close();
            stmt.close();
            conn.close();
        public static void printResultSet (ResultSet rs) throws Exception
            System.out.println("******** Fetch Starts ********");
            int line = 0;
            while (rs.next()) {
                line++;
                System.out.println("*** Row " + line + " ***");
                Array array = rs.getArray(1);
                String[] values = (String[])array.getArray();
                System.out.println ("Array is of type " + array.getBaseTypeName());
                System.out.println ("Array is of length " + values.length);
                for (int i = 0; i < values.length; i++)
                    System.out.println("Index " + i + " = " + values);
    System.out.println("******** Fetch Ends ********");

  • Migrate B-Tree Indexes of XML O-R Table to XMLIndex on Binary XML Table

    We need slight help on how to migrate existing B-TREE Indexes from XML Obj-Rel Tables to XMLIndex on new XML Binary Tables
    We use searches on Nested Collection Elements (defined unbounded in XSD)
    and related DDL for XML Obj-Rel Tables is shown below:
    CREATE TABLE TNMAB_AGREEMENT_XML
    AGREEMENT_XML xmltype,
    CREATE_BY     VARCHAR2(15) NULL ,
    CREATE_DT_GMT     TIMESTAMP NULL ,
    CREATE_CLIENT_ID VARCHAR2(65) NULL ,
    UPDATE_BY     VARCHAR2(15) NULL ,
    UPDATE_DT_GMT     TIMESTAMP NULL ,
    UPDATE_CLIENT_ID VARCHAR2(65) NULL ,
    PIC_VERSION_NUM     NUMBER(20) NULL
    XMLTYPE COLUMN AGREEMENT_XML XMLSCHEMA "AB_Agreement_V1_XMLDB.xsd" ELEMENT "Agreement"
    VARRAY AGREEMENT_XML.XMLDATA."SHIPPING_PARTY_GROUPS"
    STORE AS TABLE SHIPPING_PARTY_GROUPS_NT
    (PRIMARY KEY (NESTED_TABLE_ID, ARRAY_INDEX) ENABLE)
    VARRAY SHIPPING_PARTIES
    STORE AS TABLE SHIPPING_PARTIES_NT
    (PRIMARY KEY (NESTED_TABLE_ID, ARRAY_INDEX) ENABLE)
    VARRAY AGREEMENT_XML.XMLDATA."SALES_OFFICE_CODES"."STRING_WRAPPERS"
    STORE AS TABLE SALES_OFFICE_CODES_NT
    (PRIMARY KEY (NESTED_TABLE_ID, ARRAY_INDEX) ENABLE)
    TABLESPACE TNMAB_XMLDB_ME_DATA;
    Table has PK and Unique Index which for the Binary XML Table, it will be setup on Virtual Columns (to enforce
    Unique Constraints)
    We have 6 more Normal Indexes on this Table, some created on Nested Elements as shown below:
    -- 4 Normal B-TREE Indexes on Leaf level Elements
    create index TNMAB_AGREEMENT_XML_IDX1 on TNMAB_AGREEMENT_XML (AGREEMENT_XML.XMLDATA."AGREEMENT_VERSION")
    tablespace TNMAB_XMLDB_ME_INDX;
    create index TNMAB_AGREEMENT_XML_IDX2 on TNMAB_AGREEMENT_XML (AGREEMENT_XML.XMLDATA."LAST_UPDATED_BY")
    tablespace TNMAB_XMLDB_ME_INDX;
    create index TNMAB_AGREEMENT_XML_IDX3 on TNMAB_AGREEMENT_XML (AGREEMENT_XML.XMLDATA."LAST_UPDATED")
    tablespace TNMAB_XMLDB_ME_INDX;
    create index TNMAB_AGREEMENT_XML_IDX4 on TNMAB_AGREEMENT_XML (AGREEMENT_XML.XMLDATA."CREATION_DATE")
    tablespace TNMAB_XMLDB_ME_INDX;
    --2 Indexes created on Nested Table (Collection)
    create index TNMAB_AGREEMENT_XML_NT_IDX1 on SALES_OFFICE_CODES_NT NT(NT.STR_VAL, NT.NESTED_TABLE_ID)
    tablespace TNMAB_XMLDB_ME_INDX;
    create index TNMAB_AGREEMENT_XML_NT_IDX2 on SHIPPING_PARTIES_NT NT(NT.CUSTOMER_HOLDER.SAP_ID, NT.NESTED_TABLE_ID)
    tablespace TNMAB_XMLDB_ME_INDX;
    Could you please let us know how we should migrate above Indexes to XMLIndex format.
    Specifically, not sure how the last 2 Indexes on Nested Tables is to be defined.
    Any help or resources pointing to this would be greatly appreciated.
    Thanks for the help,
    Auro

    Can't tell due to using XMLDATA pseudocolumn. Would need a sample XML document structure that can be used to define the XPATH structure and ALSO need the database version you are using (ALL digits) to see if you would need / can use STRUCTURED or UNSTRUCTURED XMLINDEX indexes.
    See the XML Index section (http://www.liberidu.com/blog/?page_id=441) on for guidance and/or of course the XMLDB Developers Guide for your database version
    http://www.liberidu.com/blog/?page_id=441
    XMLIndex (part 1) – The Concepts
    XMLIndex (Part 2) – XMLIndex Path Subsetting
    XMLIndex (Part 3) – XMLIndex Syntax Dissected
    XMLIndex Performance and Fuzzy XPath Searches
    Structured XMLIndex (Part 1) – Rules of Numb
    Structured XMLIndex (Part 2) – Howto build a structured XMLIndex
    Structured XMLIndex (Part 3) – Building Multiple XMLIndex Structures

  • Please help me create the indexes for this XML

    Hi Mark and others,
    What is the way to create the correct index for this kind of XML (I posted earlier)? I created the indexes without using those prefixes without any problems but they do not seem to be used during processing. For 300 statutes, it took about 10 minutes! For the smplier verion, I created indexes and it took no more than 30 seconds to process more than 4000 statutes.
    <AllStatuteQueryResponse xmlns="http://crimnet.state.mn.us/mnjustice/statute/service/3.0">
    <ns1:Statutes xmlns:ns1="http://crimnet.state.mn.us/mnjustice/statute/messages/3.0">
    <ns1:Statutes>
    <ns2:StatuteId xmlns:ns2="http://crimnet.state.mn.us/mnjustice/statute/3.0">1</ns2:StatuteId>
    <ns3:Chapter xmlns:ns3="http://crimnet.state.mn.us/mnjustice/statute/3.0">84</ns3:Chapter>
    <ns4:Section xmlns:ns4="http://crimnet.state.mn.us/mnjustice/statute/3.0">82</ns4:Section>
    <ns5:Subdivision xmlns:ns5="http://crimnet.state.mn.us/mnjustice/statute/3.0">1a</ns5:Subdivision>
    <ns6:Year xmlns:ns6="http://crimnet.state.mn.us/mnjustice/statute/3.0">0</ns6:Year>
    <ns7:LegislativeSessionCode xmlns:ns7="http://crimnet.state.mn.us/mnjustice/statute/3.0">
    <ns7:StatuteCode>
    <ns7:code>4</ns7:code>
    <ns7:description>4</ns7:description>
    </ns7:StatuteCode>
    </ns7:LegislativeSessionCode>
    <ns8:SessionTextIndicator xmlns:ns8="http://crimnet.state.mn.us/mnjustice/statute/3.0">false</ns8:SessionTextIndicator>
    <ns9:HeadNoteIndicator xmlns:ns9="http://crimnet.state.mn.us/mnjustice/statute/3.0">false</ns9:HeadNoteIndicator>
    <ns10:EffectiveDate xmlns:ns10="http://crimnet.state.mn.us/mnjustice/statute/3.0">1859-01-01</ns10:EffectiveDate>
    <ns11:EnactmentDate xmlns:ns11="http://crimnet.state.mn.us/mnjustice/statute/3.0">1859-01-01</ns11:EnactmentDate>
    <ns12:RepealedIndicator xmlns:ns12="http://crimnet.state.mn.us/mnjustice/statute/3.0">false</ns12:RepealedIndicator>
    <j:DocumentLocationURI xmlns:j="http://www.it.ojp.gov/jxdm/3.0.2">
    <j:ID xsi:type="j:TextType" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">http://www.revisor.leg.state.mn.us/stats/84/82.html</j:ID>
    </j:DocumentLocationURI>
    <ns13:SummaryDescriptionText xmlns:ns13="http://crimnet.state.mn.us/mnjustice/statute/3.0">Snowmobiles-Snowmobile registration</ns13:SummaryDescriptionText>
    <ns14:StatuteFunction xmlns:ns14="http://crimnet.state.mn.us/mnjustice/statute/3.0">
    <ns14:StatuteIntegrationId>1</ns14:StatuteIntegrationId>
    Thanks!
    Ben

    Hi Mark, here is the schema. I did not register the schema, because when I processed the simpler version, I did not either and I just created the indexes. I did not create an VARRAY in the table. The DDL is simply create table CStatute_XML(id number, xmldoc xmltype).
    Schema:
    <?xml version="1.0" encoding="UTF-8"?>
    <!-- CriMNet -->
    <!-- Minnesota Criminal Justice Statute Web Service Data Dictionary -->
    <!-- Dave Everson -->
    <!-- Version 3.0 -->
    <xsd:schema targetNamespace="http://crimnet.state.mn.us/mnjustice/statute/3.0" elementFormDefault="qualified" attributeFormDefault="unqualified" version="3.0" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://crimnet.state.mn.us/mnjustice/statute/3.0">
         <xsd:element name="StatuteCode">
              <xsd:annotation>
                   <xsd:documentation>
                        This complex type is a generic structure representing code value sets defined in the Minnesota Criminal Justice Statute Service.
                        A single element of the value set contains both a code value (e.g. F) and a description (e.g. Felony).
                        The following concepts within the MNCJSS are represented by this complex type:
                             OffenseSummary
                             OffenseSummarySeverityLevel
                             LegislativeSession
                             Function
                             OffenseLevel
                             OffenseSeverityLevel
                             DetailedOffenseCode
                             GeneralOffenseCode
                   </xsd:documentation>
              </xsd:annotation>
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element name="code" type="xsd:string"/>
                        <xsd:element name="description" type="xsd:string"/>
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="StatuteId" type="xsd:integer">
              <xsd:annotation>
                   <xsd:documentation>Primary Key reference to Minnesota Criminal Justice Statute Service disseminated by CriMNet</xsd:documentation>
                   <xsd:appinfo>Statute.statuteId</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="StatuteIntegrationId" type="xsd:integer">
              <xsd:annotation>
                   <xsd:documentation>Primary Key reference to the StatuteFunction object within the Minnesota Criminal Justice Statute Service disseminated by CriMNet</xsd:documentation>
                   <xsd:appinfo>StatuteFunction.statuteIntegrationId</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="FunctionCode">
              <xsd:annotation>
                   <xsd:documentation>TBD</xsd:documentation>
                   <xsd:appinfo>StatuteFunction.Function</xsd:appinfo>
              </xsd:annotation>
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="StatuteCode"/>
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="OffenseSummaryCode">
              <xsd:annotation>
                   <xsd:documentation>TBD</xsd:documentation>
                   <xsd:appinfo>StatuteFunction.OffenseSummary</xsd:appinfo>
              </xsd:annotation>
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="StatuteCode"/>
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="OffenseSummarySeverityLevelCode">
              <xsd:annotation>
                   <xsd:documentation>TBD</xsd:documentation>
                   <xsd:appinfo>StatuteFunction.OffenseSummary.OffenseSummarySeverityLevel</xsd:appinfo>
              </xsd:annotation>
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="StatuteCode"/>
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="OffenseLevelCode">
              <xsd:annotation>
                   <xsd:documentation>TBD</xsd:documentation>
                   <xsd:appinfo>StatuteFunction.OffenseLevel</xsd:appinfo>
              </xsd:annotation>
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="StatuteCode"/>
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="OffenseSeverityLevelCode">
              <xsd:annotation>
                   <xsd:documentation>TBD</xsd:documentation>
                   <xsd:appinfo>StatuteFunction.OffenseSeverityLevel</xsd:appinfo>
              </xsd:annotation>
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="StatuteCode"/>
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="LegislativeSessionCode">
              <xsd:annotation>
                   <xsd:documentation>TBD</xsd:documentation>
                   <xsd:appinfo>StatuteChapterSection.LegislativeSession</xsd:appinfo>
              </xsd:annotation>
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="StatuteCode"/>
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="GeneralOffenseCode" nillable="true">
              <xsd:annotation>
                   <xsd:documentation>An integer (1-9) identifier of a general statute category code used for statistical analysis.</xsd:documentation>
                   <xsd:appinfo>StatuteFunction.DetailedOffenseCode.GeneralOffenseCode</xsd:appinfo>
              </xsd:annotation>
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="StatuteCode"/>
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="DetailedOffenseCode" nillable="true">
              <xsd:annotation>
                   <xsd:documentation>An identification number associated with a statute offense type in the form of nnn.nnn. From a list of 350. Corresponds to the StatuteOffinseTypeText.</xsd:documentation>
                   <xsd:appinfo>StatuteFunction.DetailedOffenseCode</xsd:appinfo>
              </xsd:annotation>
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="StatuteCode"/>
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
         <xsd:element name="Chapter" type="xsd:string">
              <xsd:annotation>
                   <xsd:documentation>A numeric identifier of a chapter within a statute.</xsd:documentation>
                   <xsd:appinfo>Statute.chapter; StatuteChapterSection.chapter</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="Section" type="xsd:string" nillable="true">
              <xsd:annotation>
                   <xsd:documentation>An integer number identifier of a section of a chapter of a statute.</xsd:documentation>
                   <xsd:appinfo>Statute.section; StatuteChapterSection.section</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="Subdivision" type="xsd:string" nillable="true">
              <xsd:annotation>
                   <xsd:documentation>An identifier of a subdivision within a code book.</xsd:documentation>
                   <xsd:appinfo>Statute.subdivision</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="HeadNoteIndicator" type="xsd:boolean">
              <xsd:annotation>
                   <xsd:documentation></xsd:documentation>
                   <xsd:appinfo>StatuteChapterSection.headNote</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>     
         <xsd:element name="Year" type="xsd:int">
              <xsd:annotation>
                   <xsd:documentation>TBD</xsd:documentation>
                   <xsd:appinfo>StatuteChapterSection.year</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="EffectiveDate" type="xsd:date" nillable="true">
              <xsd:annotation>
                   <xsd:documentation>The date a statute came into effect</xsd:documentation>
                   <xsd:appinfo>Statute.effectiveDate</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="ExpirationDate" type="xsd:date" nillable="true">
              <xsd:annotation>
                   <xsd:documentation>The date a statute was not longer effective.</xsd:documentation>
                   <xsd:appinfo>Statute.effectiveDate</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="EnactmentDate" type="xsd:date" nillable="true">
              <xsd:annotation>
                   <xsd:documentation>A date a statute was signed into law.</xsd:documentation>
                   <xsd:appinfo>Statute.enactmentDate</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="RepealedIndicator" type="xsd:boolean">
              <xsd:annotation>
                   <xsd:documentation>A date a statute number was repealed, amended, or renumbered.</xsd:documentation>
                   <xsd:appinfo>Statute.repealedFlag</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="HeadNote" type="xsd:boolean">
              <xsd:annotation>
                   <xsd:documentation></xsd:documentation>
                   <xsd:appinfo>Statute.headNote</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="SummaryDescriptionText" type="xsd:string" nillable="true">
              <xsd:annotation>
                   <xsd:documentation>A long description of a statute.</xsd:documentation>
                   <xsd:appinfo>Statute.summaryText</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="LegislativeText" type="xsd:string" nillable="true">
              <xsd:annotation>
                   <xsd:documentation>The legislative of a statute.</xsd:documentation>
                   <xsd:appinfo>StatuteChapterSection.legislativeText</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>     
         <xsd:element name="SessionTextIndicator" type="xsd:boolean">
              <xsd:annotation>
                   <xsd:documentation></xsd:documentation>
                   <xsd:appinfo>StatuteChapterSection.sessionTextFlag</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>     
         <xsd:element name="FunctionText" type="xsd:string" nillable="true">
              <xsd:annotation>
                   <xsd:documentation></xsd:documentation>
                   <xsd:appinfo>StatuteFunction.functionText</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="JuvenileOnlyIndicator" type="xsd:boolean">
              <xsd:annotation>
                   <xsd:documentation>An indicator identifying whether a statute applies to juveniles only.</xsd:documentation>
                   <xsd:appinfo>StatuteFunction.juvenileOnlyFlag</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="CrimeOfViolenceIndicator" type="xsd:boolean">
              <xsd:annotation>
                   <xsd:documentation>An indicator identifying whether a statute is a crime of violence under Minnesota statute 624 section 712 subdivision 5.</xsd:documentation>
                   <xsd:appinfo>StatuteFunction.crimeOfViolenceFlag</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="EnhanceableIndicator" type="xsd:boolean">
              <xsd:annotation>
                   <xsd:documentation>An indicator identifying whether the charges are enhanceable by specific factors (the definition of enhanceable is pending review).</xsd:documentation>
                   <xsd:appinfo>StatuteFunction.enhanceableFlag</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="TargetedMisdemeanorIndicator" type="xsd:boolean">
              <xsd:annotation>
                   <xsd:documentation>An indicator identifying whether a statute is a targeted misdemeanor as defined in Minnnesota Statute 299C.10, subdivision. 1(d).</xsd:documentation>
                   <xsd:appinfo>StatuteFunction.targetedMisdemeanorFlag</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="MandatoryAppearanceIndicator" type="xsd:boolean">
              <xsd:annotation>
                   <xsd:documentation></xsd:documentation>
                   <xsd:appinfo>StatuteFunction.mandatoryAppearanceFlag</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="RegisterableOffenseIndicator" type="xsd:boolean">
              <xsd:annotation>
                   <xsd:documentation></xsd:documentation>
                   <xsd:appinfo>StatuteFunction.registerableOffenseFlag</xsd:appinfo>
              </xsd:annotation>
         </xsd:element>
         <xsd:element name="StatuteFunction">
              <xsd:annotation>
                   <xsd:documentation></xsd:documentation>
                   <xsd:appinfo>StatuteFunction</xsd:appinfo>
              </xsd:annotation>
              <xsd:complexType>
                   <xsd:sequence>
                        <xsd:element ref="StatuteIntegrationId" />
                        <xsd:element ref="FunctionCode"/>
                        <xsd:element ref="FunctionText" minOccurs="0" maxOccurs="1"/>                    
                        <xsd:element ref="CrimeOfViolenceIndicator"/>
                        <xsd:element ref="EnhanceableIndicator"/>
                        <xsd:element ref="TargetedMisdemeanorIndicator"/>
                        <xsd:element ref="RegisterableOffenseIndicator"/>                    
                        <xsd:element ref="JuvenileOnlyIndicator"/>
                        <xsd:element ref="MandatoryAppearanceIndicator"/>                                        
                        <xsd:element ref="OffenseLevelCode" minOccurs="0" maxOccurs="1"/>
                        <xsd:element ref="GeneralOffenseCode" minOccurs="0" maxOccurs="1"/>
                        <xsd:element ref="DetailedOffenseCode" minOccurs="0" maxOccurs="1"/>
                        <xsd:element ref="OffenseSummaryCode" minOccurs="0" maxOccurs="1"/>
                        <xsd:element ref="OffenseSummarySeverityLevelCode" minOccurs="0" maxOccurs="1"/>
                        <xsd:element ref="OffenseSeverityLevelCode" minOccurs="0" maxOccurs="1"/>
                   </xsd:sequence>
              </xsd:complexType>
         </xsd:element>
    </xsd:schema>
    Query:
    first part to get the statute ID numbers,
    insert into CriMNet_Statutes
         select cs.StatuteId, cs.Chapter, cs.Section, cs.Subdivision, cs.Year, cs.LegCode,
              cs.LegDesc, cs.SessionTextIndicator, cs.HeadNoteIndicator,
              to_date(cs.EffectiveDate, 'yyyy/mm/dd') as eDate,
              to_date(cs.EnactmentDate, 'yyyy/mm/dd') as EnDate,
              cs.RepealedIndicator, cs.SummaryDescriptionText
         from Cstatute_xml,          
         xmltable
              xmlnamespaces
                   default 'http://crimnet.state.mn.us/mnjustice/statute/3.0',     
                   --- or 'http://crimnet.state.mn.us/mnjustice/statute/3.0' as "cs"
                   'http://crimnet.state.mn.us/mnjustice/statute/service/3.0' as "cx",
                   'http://crimnet.state.mn.us/mnjustice/statute/messages/3.0' as "ns1"                    
              '/cx:AllStatuteQueryResponse/ns1:Statutes/ns1:Statutes'               
              --- '/AllStatuteQueryResponse//ns:Statutes' --- produces an extra row
              passing SXMLDOC
              columns
              StatuteId     varchar2(10)     path '//StatuteId',
              Chapter          varchar2(10)     path '//Chapter',
              Section          varchar2(20)     path '//Section',
              Subdivision     varchar2(20)     path '//Subdivision',
              Year          number          path '//Year',     
              LegCode          varchar2(10)     path '//LegislativeSessionCode/StatuteCode/code',
              LegDesc          varchar2(10)     path '//LegislativeSessionCode/StatuteCode/description',
              SessionTextIndicator varchar2(10) path '//SessionTextIndicator',
              HeadNoteIndicator varchar2(10)     path '//HeadNoteIndicator',
              EffectiveDate     varchar2(15)     path '//EffectiveDate',
              EnactmentDate     varchar2(15)     path '//EnactmentDate',
              RepealedIndicator varchar2(10)     path '//RepealedIndicator',
              SummaryDescriptionText varchar2(150) path '//SummaryDescriptionText'     
         ) cs;
    Second part to get the function code for each statute ID (one ID to many function codes).
    declare
              v_statuteID     number;
              v_statuteIDC     varchar2(10);
              cursor c_cmns is
              select statuteid from CriMNet_Statutes;
         begin
              for v_cmns in c_cmns loop
                   v_StatuteID := v_cmns.StatuteID;
                   v_statuteIDC := to_char(v_statuteID);
                   insert into CriMNet_Statute_Function
                   select v_StatuteID, cf.* from Cstatute_xml,
                   xmltable
                        xmlnamespaces
                             'http://crimnet.state.mn.us/mnjustice/statute/3.0' as "cs",
                             'http://crimnet.state.mn.us/mnjustice/statute/service/3.0' as "cx",
                             'http://crimnet.state.mn.us/mnjustice/statute/messages/3.0' as "ns1"                         
                        'for $cxm in /cx:AllStatuteQueryResponse/ns1:Statutes/ns1:Statutes[cs:StatuteId = $val/pStatuteId]/cs:StatuteFunction
                        return
                        <cs:CSFunction>
                             <cs:StatuteIntegrationId>{$cxm//cs:StatuteIntegrationId}</cs:StatuteIntegrationId>
                             <cs:FunctionCode>{$cxm//cs:FunctionCode/cs:StatuteCode/cs:code}</cs:FunctionCode>
                             <cs:FunctionDesc>{$cxm//cs:FunctionCode/cs:StatuteCode/cs:description}</cs:FunctionDesc>
                             <cs:CrimeOfViolenceIndicator>{$cxm//cs:CrimeOfViolenceIndicator}</cs:CrimeOfViolenceIndicator>
                             <cs:EnhanceableIndicator>{$cxm//cs:EnhanceableIndicator}</cs:EnhanceableIndicator>
                             <cs:TargetedMisdIndicator>{$cxm//cs:TargetedMisdemeanorIndicator}</cs:TargetedMisdIndicator>
                             <cs:RegisterableOffIndicator>{$cxm//cs:RegisterableOffenseIndicator}</cs:RegisterableOffIndicator>
                             <cs:JuvenileOnlyIndicator>{$cxm//cs:JuvenileOnlyIndicator}</cs:JuvenileOnlyIndicator>
                             <cs:MandatoryAppIndicator>{$cxm//cs:MandatoryAppearanceIndicator}</cs:MandatoryAppIndicator>
                             <cs:OffenseLevelCode>{$cxm//cs:OffenseLevelCode/cs:StatuteCode/cs:code}</cs:OffenseLevelCode>
                             <cs:OffenseLevelDesc>{$cxm//cs:OffenseLevelCode/cs:StatuteCode/cs:description}</cs:OffenseLevelDesc>
                             <cs:GeneralOffenseCode>{$cxm//cs:GeneralOffenseCode/cs:StatuteCode/cs:code}</cs:GeneralOffenseCode>
                             <cs:GeneralOffenseDesc>{$cxm//cs:GeneralOffenseCode/cs:StatuteCode/cs:description}</cs:GeneralOffenseDesc>
                             <cs:DetailedOffenseCode>{$cxm//cs:DetailedOffenseCode/cs:StatuteCode/cs:code}</cs:DetailedOffenseCode>
                             <cs:DetailedOffenseDesc>{$cxm//cs:DetailedOffenseCode/cs:StatuteCode/cs:description}</cs:DetailedOffenseDesc>
                             <cs:OffenseSummaryCode>{$cxm//cs:OffenseSummaryCode/cs:StatuteCode/cs:code}</cs:OffenseSummaryCode>
                             <cs:OffenseSummaryDesc>{$cxm//cs:OffenseSummaryCode/cs:StatuteCode/cs:description}</cs:OffenseSummaryDesc>
                             <cs:OffenseSumSeverityLevelCode>{$cxm//cs:OffenseSummarySeverityLevelCode/cs:StatuteCode/cs:code}</cs:OffenseSumSeverityLevelCode>
                             <cs:OffenseSumSeverityLevelDesc>{$cxm//cs:OffenseSummarySeverityLevelCode/cs:StatuteCode/cs:description}</cs:OffenseSumSeverityLevelDesc>
                        </cs:CSFunction>'                              
                        passing SXMLDOC, xmlelement("pStatuteId", v_statuteIDC) as "val"
                        columns
                        StatuteIntegrationId     number     path '/cs:CSFunction/cs:StatuteIntegrationId',
                        FunctionCode          varchar2(10) path '/cs:CSFunction/cs:FunctionCode',
                        FunctionDesc          varchar2(30)     path '/cs:CSFunction/cs:FunctionDesc',
                        CrimeOfViolenceIndicator varchar2(10)     path '/cs:CSFunction/cs:CrimeOfViolenceIndicator',
                        EnhanceableIndicator     varchar2(10)     path '/cs:CSFunction/cs:EnhanceableIndicator',
                        TargetedMisdIndicator     varchar2(10)     path '/cs:CSFunction/cs:TargetedMisdIndicator',
                        RegisterableOffIndicator varchar2(10)     path '/cs:CSFunction/cs:RegisterableOffIndicator',
                        JuvenileOnlyIndicator     varchar2(10)     path '/cs:CSFunction/cs:JuvenileOnlyIndicator',
                        MandatoryAppIndicator     varchar2(10)     path '/cs:CSFunction/cs:MandatoryAppIndicator',
                        OffenseLevelCode     varchar2(10)     path '/cs:CSFunction/cs:OffenseLevelCode',
                        OffenseLevelDesc     varchar2(40)     path '/cs:CSFunction/cs:OffenseLevelDesc',
                        GeneralOffenseCode     varchar2(10)     path '/cs:CSFunction/cs:GeneralOffenseCode',
                        GeneralOffenseDesc     varchar2(60)     path '/cs:CSFunction/cs:GeneralOffenseDesc',
                        DetailedOffenseCode     varchar2(10)     path '/cs:CSFunction/cs:DetailedOffenseCode',
                        DetailedOffenseDesc     varchar2(60)     path '/cs:CSFunction/cs:DetailedOffenseDesc',
                        OffenseSummaryCode     varchar2(10)     path '/cs:CSFunction/cs:OffenseSummaryCode',
                        OffenseSummaryDesc     varchar2(60)     path '/cs:CSFunction/cs:OffenseSummaryDesc',
                        OffenseSumSeverityLevelCode varchar2(10)     path '/cs:CSFunction/cs:OffenseSumSeverityLevelCode',
                        OffenseSumSeverityLevelDesc varchar2(30)     path '/cs:CSFunction/cs:OffenseSumSeverityLevelDesc'          
                   ) cf;
                   ---dbms_output.put_line('Statute ID = ' || v_StatuteID);
              end loop;
         end;
    You mentioned that I should include the namespace in the existsnode function but I did not. I am going to try after including it. Thanks.
    Ben

Maybe you are looking for