How to create index on a xmltype column stored as CLOB

actually i have two problems.
i uploaded this schemaA.xsd file into xmldb repository without problems. registration also went ok.
BEGIN
DBMS_XMLSCHEMA.registerSchema(
schemaURL => 'http://xmlns.example.com/xdb/documentation/schemaA.xsd'
,schemaDoc => sys.UriFactory.getUri('/home/dev/schemaA.xsd')
,local => TRUE
,genBean => false
,genTypes => TRUE
,genTables => false
,enableHierarchy => DBMS_XMLSCHEMA.ENABLE_HIERARCHY_NONE
END;
then i run this:
create table pf_table_a(
     id VARCHAR2(100) primary key,
     xsd VARCHAR2(3000),
xml_document XMLType
) XMLTYPE COLUMN xml_document
STORE AS CLOB
XMLSCHEMA "http://xmlns.example.com/xdb/documentation/schemaA.xsd"
ELEMENT "order";
and got this error:
SQL> @d:\usr\dev\perftest\create_tables.sql
Table created.
create table pf_table_a(
ERROR at line 1:
ORA-00955: name is already used by an existing object
anyway the table was created. so i went on to create indexes.
SQL> create index pf_a_index on pf_table_a(extractValue(OBJECT_VALUE, '/order@or
derNo'));
create index pf_a_index on pf_table_a(extractValue(OBJECT_VALUE, '/order@orderNo
ERROR at line 1:
ORA-04063: table "BAUSER1.PF_TABLE_A" has errors
this of course is wrong. because the command is for creating index of a XMLTYPE table. no a column. but what is the correct command? thanks.
jack.

actually i have two problems.
i uploaded this schemaA.xsd file into xmldb repository without problems. registration also went ok.
BEGIN
DBMS_XMLSCHEMA.registerSchema(
schemaURL => 'http://xmlns.example.com/xdb/documentation/schemaA.xsd'
,schemaDoc => sys.UriFactory.getUri('/home/dev/schemaA.xsd')
,local => TRUE
,genBean => false
,genTypes => TRUE
,genTables => false
,enableHierarchy => DBMS_XMLSCHEMA.ENABLE_HIERARCHY_NONE
END;
then i run this:
create table pf_table_a(
     id VARCHAR2(100) primary key,
     xsd VARCHAR2(3000),
xml_document XMLType
) XMLTYPE COLUMN xml_document
STORE AS CLOB
XMLSCHEMA "http://xmlns.example.com/xdb/documentation/schemaA.xsd"
ELEMENT "order";
and got this error:
SQL> @d:\usr\dev\perftest\create_tables.sql
Table created.
create table pf_table_a(
ERROR at line 1:
ORA-00955: name is already used by an existing object
anyway the table was created. so i went on to create indexes.
SQL> create index pf_a_index on pf_table_a(extractValue(OBJECT_VALUE, '/order@or
derNo'));
create index pf_a_index on pf_table_a(extractValue(OBJECT_VALUE, '/order@orderNo
ERROR at line 1:
ORA-04063: table "BAUSER1.PF_TABLE_A" has errors
this of course is wrong. because the command is for creating index of a XMLTYPE table. no a column. but what is the correct command? thanks.
jack.

Similar Messages

  • Creating Indexes within an XMLType column

    Hi,
    I have following XML document stored as XMLType column,
    <ocaStatus xmlns="http://xmlbeans.apache.org/ocastatus"><status><statusCode>934</statusCode><statusDate>Wed Apr 07 16:05:53 GMT+05:30 2010</statusDate><userId>u0121845</userId><comment>Sent to LTC</comment></status><status><statusCode>934</statusCode><statusDate>Wed Apr 07 15:58:25 GMT+05:30 2010</statusDate><userId>u0121845</userId><comment>Sent to LTC</comment></status><status><statusCode>934</statusCode><statusDate>Wed Apr 07 15:54:02 GMT+05:30 2010</statusDate><userId>u0121845</userId><comment>Sent to LTC</comment></status><status><statusCode>750</statusCode><statusDate>2010-03-31 12:39:41.580 GMT+05:30</statusDate><userId>u0121845</userId><comment>Document Metadata is correct.</comment></status><status><statusCode>934</statusCode><statusDate>2010-03-31 12:39:41.580 GMT+05:30</statusDate><userId>u0121845</userId><comment>Sent to LTC</comment></status><status><statusCode>932</statusCode><statusDate>2010-03-31 12:39:41.580 GMT+05:30</statusDate><userId>u0121845</userId><comment>Loaded to Novus</comment></status><status><statusCode>700</statusCode><statusDate>2010-03-31 12:39:41.580 GMT+05:30</statusDate><userId>u0121845</userId><comment>Document is deleted from OCA.</comment></status></ocaStatus>
    I created following Indexes within the XML,
    CREATE INDEX "OCA_DEV"."OCA_STATUS_CODE_INDEX" ON "OCA_DEV"."DOCUMENT_STATUS_XML" (EXTRACTVALUE('/ocaStatus/status/statusCode'));
    CREATE INDEX "OCA_DEV"."OCA_STATUS_DATE_INDEX" ON "OCA_DEV"."DOCUMENT_STATUS_XML" (EXTRACTVALUE('/ocaStatus/status/statusDate'));
    However the problem is that I will be having multiple status within each XML which violates the Indexing.
    Is there any way I can still create the Indexes allowing multiple status values in each XML?
    Thanks in advance.

    Hi,
    You may want to store your document as a schema-based, object-relational XMLType to achieve that.
    Then you'll be able to create indexes on the nested table used to store each "status" element.
    Here's an example based on your sample document.
    1) First, create and register a schema. The following is basic but sufficient here, let's call it "ocastatus.xsd" :
    <?xml version="1.0"?>
    <xsd:schema
    targetNamespace="http://xmlbeans.apache.org/ocastatus"
    xmlns="http://xmlbeans.apache.org/ocastatus"
    elementFormDefault="qualified"
    xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xdb="http://xmlns.oracle.com/xdb">
    <xsd:element name="ocaStatus" type="OCASTATUS_TYPEType"/>
    <xsd:complexType name="OCASTATUS_TYPEType" xdb:SQLType="OCASTATUS_TYPE">
      <xsd:sequence>
       <xsd:element name="status" type="STATUS_TYPEType" xdb:SQLName="status" maxOccurs="unbounded" xdb:SQLCollType="STATUS_V"/>
      </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="STATUS_TYPEType" xdb:SQLType="STATUS_TYPE">
      <xsd:sequence>
       <xsd:element name="statusCode" type="xsd:double" xdb:SQLName="statusCode" xdb:SQLType="NUMBER"/>
       <xsd:element name="statusDate" xdb:SQLName="statusDate" xdb:SQLType="VARCHAR2">
        <xsd:simpleType>
         <xsd:restriction base="xsd:string">
          <xsd:maxLength value="50"/>
         </xsd:restriction>
        </xsd:simpleType>
       </xsd:element>
       <xsd:element name="userId" xdb:SQLName="userId" xdb:SQLType="VARCHAR2">
        <xsd:simpleType>
         <xsd:restriction base="xsd:string">
          <xsd:maxLength value="50"/>
         </xsd:restriction>
        </xsd:simpleType>
       </xsd:element>
       <xsd:element name="comment" xdb:SQLName="comment" xdb:SQLType="VARCHAR2">
        <xsd:simpleType>
         <xsd:restriction base="xsd:string">
          <xsd:maxLength value="100"/>
         </xsd:restriction>
        </xsd:simpleType>
       </xsd:element>
      </xsd:sequence>
    </xsd:complexType>
    </xsd:schema>Registering...
    BEGIN
    dbms_xmlschema.registerSchema(
      schemaURL => 'ocastatus.xsd',
      schemaDoc => xmltype(bfilename('XSD_DIR','ocastatus.xsd'), nls_charset_id('AL32UTF8')),
      genTypes => true,
      genTables => false
    END;2) Table definition :
    CREATE TABLE oca_status (
      num NUMBER,
      doc XMLTYPE
      XMLTYPE doc STORE AS OBJECT RELATIONAL
       XMLSCHEMA "ocastatus.xsd"
       ELEMENT "ocaStatus"
       VARRAY doc.xmldata."status" STORE AS TABLE oca_status_tab
    CREATE INDEX oca_status_tab_idx1 ON oca_status_tab("statusCode");
    CREATE INDEX oca_status_tab_idx2 ON oca_status_tab("statusDate");3) Inserting document...
    INSERT INTO oca_status (num, doc)
    VALUES(1, xmltype('<ocaStatus xmlns="http://xmlbeans.apache.org/ocastatus">
      <status>
        <statusCode>934</statusCode>
        <statusDate>Wed Apr 07 16:05:53 GMT+05:30 2010</statusDate>
        <userId>u0121845</userId>
        <comment>Sent to LTC</comment>
      </status>
      <status>
        <statusCode>934</statusCode>
        <statusDate>Wed Apr 07 15:58:25 GMT+05:30 2010</statusDate>
        <userId>u0121845</userId>
        <comment>Sent to LTC</comment>
      </status>
      <status>
        <statusCode>934</statusCode>
        <statusDate>Wed Apr 07 15:54:02 GMT+05:30 2010</statusDate>
        <userId>u0121845</userId>
        <comment>Sent to LTC</comment>
      </status>
      <status>
        <statusCode>750</statusCode>
        <statusDate>2010-03-31 12:39:41.580 GMT+05:30</statusDate>
        <userId>u0121845</userId>
        <comment>Document Metadata is correct.</comment>
      </status>
      <status>
        <statusCode>934</statusCode>
        <statusDate>2010-03-31 12:39:41.580 GMT+05:30</statusDate>
        <userId>u0121845</userId>
        <comment>Sent to LTC</comment>
      </status>
      <status>
        <statusCode>932</statusCode>
        <statusDate>2010-03-31 12:39:41.580 GMT+05:30</statusDate>
        <userId>u0121845</userId>
        <comment>Loaded to Novus</comment>
      </status>
      <status>
        <statusCode>700</statusCode>
        <statusDate>2010-03-31 12:39:41.580 GMT+05:30</statusDate>
        <userId>u0121845</userId>
        <comment>Document is deleted from OCA.</comment>
      </status>
    </ocaStatus>')
    );Verifying index use (XPath rewrite) ...
    SQL> EXPLAIN PLAN FOR
      2  SELECT * from oca_status x
      3  WHERE existsnode(x.doc, '//status[statusCode="934"]') = 1;
    Explicité.
    SQL> SELECT * FROM TABLE(dbms_xplan.display);
    PLAN_TABLE_OUTPUT
    Plan hash value: 1840289382
    | Id  | Operation                     | Name                | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT              |                     |     1 |  7938 |     4  (25)| 00:00:01 |
    |*  1 |  TABLE ACCESS FULL            | OCA_STATUS_TAB      |     1 |  2145 |     4   (0)| 00:00:01 |
    |   2 |  NESTED LOOPS                 |                     |     1 |  7938 |     4  (25)| 00:00:01 |
    |   3 |   SORT UNIQUE                 |                     |     4 |  8580 |     2   (0)| 00:00:01 |
    |   4 |    TABLE ACCESS BY INDEX ROWID| OCA_STATUS_TAB      |     4 |  8580 |     2   (0)| 00:00:01 |
    |*  5 |     INDEX RANGE SCAN          | OCA_STATUS_TAB_IDX1 |     4 |       |     1   (0)| 00:00:01 |
    |   6 |   TABLE ACCESS BY INDEX ROWID | OCA_STATUS          |     1 |  5793 |     1   (0)| 00:00:01 |
    |*  7 |    INDEX UNIQUE SCAN          | SYS_C00243981       |     1 |       |     0   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       1 - filter("NESTED_TABLE_ID"=:B1)
       5 - access("statusCode"=934)
       7 - access("NESTED_TABLE_ID"="X"."SYS_NC0000900010$")
    Note
       - dynamic sampling used for this statement
    25 ligne(s) sélectionnée(s).
    SQL> Regards.

  • How to create index on a varchar column that represent date?

    Hello there,
    I have a column in my table that is a VARCHAR2 and represent a datetime like '2010-08-23 19:00:00' I want to create an index on it and with an specific large like '2010-08-23 19' so i can filter per HOURS.
    Any one knows the sentence for this?
    Thanx in advance

    Vladimir Zakharychev wrote:
    I'd highly recommend you heed the advice given: store dates as DATE, numbers as NUMBER, strings as VARCHAR2. I can't imagine any valid reason for storing dates like that (except the undisputable "because I want it that way.") You are likely to see all sorts of inefficiencies with your current design (it will not sort correctly, for example, because it will sort strings, not dates, and the rules for sorting them are different.) The function-based index you created will only work if your query will use that same exact function you created the index on.Not to mention that there is no way the database can enforce the "date" data to actually be a valid date . . . and there will come a time that the application *will not" enforce it ...                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                   

  • How to create index on xmltype column

    I have a table having only one column xmlcontent (xmltype). This table stores xml data of about 10GB size. I'm using extract value to move the data to staging tables.
    How can I create index on xmltype column?
    Create index indexname on table (column) doesn't seem to work.
    Sample xmlstructure is given below
    <Root>
    <Type>Insert</Type>
    <Date>2006-12-29</Date>
    <Source>8</Source>
    <id>data</id>
    <key_flds>
    <fld><id>Key1</id><val>C</val></fld>
    <fld><id>Key2</id><val>429672</val></fld>
    <fld><id>Key3</id><val>8</val></fld>
    </key_flds>
    </Root>
    I need to do extract value on all tags and move them to corresponding relational tables.

    Hi, you need to create them using something like this (what I have used and work rather well - if I did not load the xml into an xml table, the processing took about 10 minutes, while the indexed xml table took just a few seconds). statute_xml is the table name and sxmldoc is the xml column/field.
    create index desc_idx on statute_xml
    (sxmldoc.existsNode('/SimpleTypeCompanion/EnumerationValue/@description'))
    create index sid_idx on statute_xml
    (sxmldoc.existsNode
    ('/SimpleTypeCompanion/EnumerationValue/Text')
    create index effdate_idx on statute_xml
    (sxmldoc.existsNode
    ('/SimpleTypeCompanion/EnumerationValue/@effectiveDate')
    Hope this helps.
    Ben

  • How to create indexes on ODS ?

    Hello friends ,
    Need some help .
    Could any one please let me know how to create indexes on ODS ?
    How Indexes are useful on ODS ?
    Thanks in advance
    Regards

    Dear Akshay,
    Below is the information about indexes and there creation for ODS.
    You can search a table for data records that satisfy certain search criteria faster using an index.
    An index can be considered a copy of a database table that has been reduced to certain fields. This copy is always in sorted form. Sorting provides faster access to the data records of the table, for example using a binary search. The index also contains a pointer to the corresponding record of the actual table so that the fields not contained in the index can also be read.
    The primary index is distinguished from the secondary indexes of a table. The primary index contains the key fields of the table and a pointer to the non-key fields of the table. The primary index is created automatically when the table is created in the database.
    You can also create further indexes on a table in the ABAP Dictionary. These are called secondary indexes.Under Indexes, you can create secondary indexes by using the context menu in order to improve the load and query performance of the ODS object This is necessary if the table is frequently accessed in a way that does not take advantage of the sorting of the primary index for the access.
    The database system sometimes does not use a suitable index for a selection, even if there is one. The index used depends on the optimizer used for the database system. You should therefore check if the index you created is also used for the selection (see How to Check if an Index is Used).).
    Creating an additional index could also have side effects on the performance. This is because an index that was used successfully for selection might not be used any longer by the optimizer if the optimizer estimates (sometimes incorrectly) that the newly created index is more selective.
    The indexes on a table should therefore be as disjunct as possible, that is they should contain as few fields in common as possible. If two indexes on a table have a large number of common fields, this could make it more difficult for the optimizer to choose the most selective index.
    Leaving content frame.
    With Regards,
    Prafulla Singh

  • How to create indexes using CREATE TABLE statement

    Hi,
    Can anyone please tell me how to create indexes using CREATE TABLE staement? This point is part SQL Expert exam (1Z0-047) and please guide me to use which books for this particular exam.
    Thanks in advance.

    Can anyone please tell me how to create indexes using CREATE TABLE staement?e.g. creating a primary key or a unique constraint will generate indexes along with the create table syntax:
    SQL> create table t (a integer primary key, b integer unique)
    Table created.
    SQL> select   index_name, index_type, uniqueness
      from   user_indexes
    where   table_name = 'T'
    INDEX_NAME                     INDEX_TYPE                  UNIQUENES
    SYS_C0016575                   NORMAL                      UNIQUE  
    SYS_C0016574                   NORMAL                      UNIQUE  
    2 rows selected.

  • Create Index on another schema table stored in my table

    Hi,
    I want to create index on a table column which is in another schema from my schema and the index to be stored in my schema.
    ex: current user 'hr'
    sql>create index idx1 on scott.emp(eno);
    Does the above query works??
    thanks,
    Sri

    Why cant you give a try?
    Are you getting any error message?
    See below..
    SQL> show user
    USER is "SCOTT"
    SQL> grant select on emp to hr;
    Grant succeeded.
    SQL> conn
    Enter user-name: hr@***
    Enter password:
    Connected.
    SQL> show user
    USER is "HR"
    SQL> create index ndx on scott.emp(sal);
    create index ndx on scott.emp(sal)
    ERROR at line 1:
    ORA-01031: insufficient privileges
    SQL> conn
    Enter user-name: system@*******
    Enter password:
    Connected.
    SQL> create index ndx on scott.emp(sal);
    Index created.
    SQL> drop index ndx;
    Index dropped.
    SQL> grant create any index to hr;
    Grant succeeded.
    SQL> conn
    Enter user-name: hr@*******
    Enter password:
    Connected.
    SQL> create index ndx on scott.emp(sal);
    Index created.Edited by: jeneesh on Oct 8, 2012 3:53 PM

  • How to publish XML document whose source is stored in clob column

    I have to create simple application:
    in one table are stored some information about XML documents (date of creation, etc.) and the document source itself in one (unfortunatelly clob type) column.
    The point is to anable users finding document(s) and viewing it.
    Using forms I can search and display information about documents. But I have no idea how to publish XML document whose source is stored in clob column.
    I am using Oracle Portal 3.0 on NT.
    Thanks in advance.

    Hi Sergio,
    This link might be helpful:
    http://www.oracle.com/webfolder/technetwork/tutorials/obe/db/apex/r31/apex31nf/apex31blob.htm
    Also refer the BLOB Download Format Mask :
    {message:id=9716335}
    Here I have given the format mask for APEX 4.0, which will slightly differ for 3.2.1 and proposed changes
    in the format mask are:
    1) Format Mask: DOWNLOAD
    2) Content Disposition: Inline
    This will be achieved with it:
    >
    But now, my user would like to know if it´s possible that APEX application can OPEN some of these files stored on this BLOB column WITHOUT download it.
    My user would like to see a hiperlink (or button) that, if pressed/acessed, can open a new page (or a page inside application) with the document. He doesn´t need to edit this oppened file. He only wants to see it.
    >
    Hope it helps!
    Regards,
    Kiran

  • How to create index on XMLType column extension?

    I have an XMLType column named "info" whose corresponding global element has a complexType "InfoType" in namespace "http://example.org/ord". The "InfoType" complexType is extended in two namespaces, "http://example.org/info/zipcode" and "http://example.org/info/street". How do I create a unique index using an "InfoType" element contributed from one of the extension namespaces?
    I have included below a SQL script that completely describes the problem.
    Thanks in advance for your assistance?
    - Ron
    BEGIN
    DBMS_XMLSCHEMA.registerSchema(
    'chapter04prod.xsd',
    '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns="http://example.org/prod"
    targetNamespace="http://example.org/prod"
    elementFormDefault="unqualified">
    <xsd:complexType name="ItemsType">
    <xsd:sequence>
    <xsd:element name="product" type="ProductType"/>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="ProductType">
    <xsd:sequence>
    <xsd:element name="number" type="xsd:integer"/>
    <xsd:element name="name" type="xsd:string"/>
    <xsd:element name="size" type="SizeType"/>
    <xsd:element name="color" type="ColorType"/>
    </xsd:sequence>
    </xsd:complexType>
    <xsd:complexType name="SizeType">
    <xsd:simpleContent>
    <xsd:extension base="xsd:integer">
    <xsd:attribute name="system" type="xsd:string"/>
    </xsd:extension>
    </xsd:simpleContent>
    </xsd:complexType>
    <xsd:complexType name="ColorType">
    <xsd:attribute name="value" type="xsd:string"/>
    </xsd:complexType>
    </xsd:schema>',
    TRUE,
    TRUE,
    FALSE,
    FALSE);
    END;
    BEGIN
    DBMS_XMLSCHEMA.registerSchema(
    'chapter04ord1.xsd',
    '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    targetNamespace="http://example.org/ord"
    xmlns="http://example.org/ord"
    xmlns:prod="http://example.org/prod"
    elementFormDefault="qualified">
    <xsd:import namespace="http://example.org/prod"
    schemaLocation="chapter04prod.xsd"/>
    <xsd:simpleType name="OrderNumType">
    <xsd:restriction base="xsd:string"/>
    </xsd:simpleType>
    <xsd:complexType name="InfoType"/>
    <xsd:complexType name="CustomerType">
    <xsd:all>
    <xsd:element name="name" type="CustNameType"/>
    <xsd:element name="number" type="xsd:integer"/>
    <xsd:element name="info" type="InfoType" form="unqualified"/>
    </xsd:all>
    </xsd:complexType>
    <xsd:simpleType name="CustNameType">
    <xsd:restriction base="xsd:string"/>
    </xsd:simpleType>
    <xsd:element name="order" type="OrderType"/>
    <xsd:element name="customer" type="CustomerType"/>
    <xsd:complexType name="OrderType">
    <xsd:sequence>
    <xsd:element name="number" type="OrderNumType"/>
    <xsd:element name="customer" type="CustomerType"
    maxOccurs="unbounded"/>
    <xsd:element name="items" type="prod:ItemsType"/>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:schema>',
    TRUE,
    TRUE,
    FALSE,
    FALSE);
    END;
    BEGIN
    DBMS_XMLSCHEMA.registerSchema(
    'chapter04infozipcode.xsd',
    '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:ord="http://example.org/ord"
    xmlns="http://example.org/info/zipcode"
    targetNamespace="http://example.org/info/zipcode"
    elementFormDefault="unqualified">
    <xsd:import namespace="http://example.org/ord"
    schemaLocation="chapter04ord1.xsd"/>
    <xsd:complexType name="InfoType">
    <xsd:complexContent>
    <xsd:extension base="ord:InfoType">
    <xsd:sequence>
    <xsd:element name="zipcode" type="xsd:string"/>
    </xsd:sequence>
    </xsd:extension>
    </xsd:complexContent>
    </xsd:complexType>
    </xsd:schema>',
    TRUE,
    TRUE,
    FALSE,
    FALSE);
    END;
    BEGIN
    DBMS_XMLSCHEMA.registerSchema(
    'chapter04infostreet.xsd',
    '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:ord="http://example.org/ord"
    xmlns="http://example.org/info/street"
    targetNamespace="http://example.org/info/street"
    elementFormDefault="unqualified">
    <xsd:import namespace="http://example.org/ord"
    schemaLocation="chapter04ord1.xsd"/>
    <xsd:complexType name="InfoType">
    <xsd:complexContent>
    <xsd:extension base="ord:InfoType">
    <xsd:sequence>
    <xsd:element name="street" type="xsd:string"/>
    </xsd:sequence>
    </xsd:extension>
    </xsd:complexContent>
    </xsd:complexType>
    </xsd:schema>',
    TRUE,
    TRUE,
    FALSE,
    FALSE);
    END;
    BEGIN
    DBMS_XMLSCHEMA.registerSchema(
    'chapter04nonamespace.xsd',
    '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:ord="http://example.org/ord">
    <xsd:import namespace="http://example.org/ord"
    schemaLocation="chapter04ord1.xsd"/>
    <xsd:element name="info" type="ord:InfoType">
    </xsd:schema>',
    TRUE,
    TRUE,
    FALSE,
    FALSE);
    END;
    CREATE TABLE customer (
    name VARCHAR(64),
    number INTEGER,
    info XMLTYPE)
    XMLType info STORE AS OBJECT RELATIONAL
    XMLSCHEMA "chapter04nonamespace.xsd"
    ELEMENT "info";
    INSERT INTO customer (name, number, info)
    VALUES ('George Jones', 1,
    XMLType(
    '<info xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:street="http://example.org/info/zipcode"
    xsi:type="zipcode:InfoType">
    <zipcode>28877</zipcode>
    </info>');
    INSERT INTO customer (name, number, info)
    VALUES ('Jim Jones', 2,
    XMLType(
    '<info xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:street="http://example.org/info/street"
    xsi:type="street:InfoType">
    <street>3456 Autumn Lane</street>
    </info>');
    SELECT name,
    extractValue(info, '/info/street')
    FROM customer
    WHERE extractValue(info, '/info/street/text()') LIKE '3456%';
    -- How does one create a unique index as follows?
    CREATE UNIQUE INDEX customer_infostreet ON customer (??????);
    -- The following insert should fail with unique index violation!
    INSERT INTO customer (name, number, info)
    VALUES ('Jerry Jones', 3,
    XMLType(
    '<info xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xmlns:street="http://example.org/info/street"
    xsi:type="street:InfoType">
    <street>3456 Autumn Lane</street>
    </info>');

    Ron
    Glad you found a solution.. However a more efficient solution is show below
    SQL> connect sys/ as sysdba
    Enter password:
    Connected.
    SQL> set define on
    SQL> --
    SQL> define USERNAME = OTNTEST
    SQL> --
    SQL> def PASSWORD = OTNTEST
    SQL> --
    SQL> def USER_TABLESPACE = USERS
    SQL> --
    SQL> def TEMP_TABLESPACE = TEMP
    SQL> --
    SQL> drop user &USERNAME cascade
      2  /
    old   1: drop user &USERNAME cascade
    new   1: drop user OTNTEST cascade
    User dropped.
    SQL> grant connect, resource to &USERNAME identified by &PASSWORD
      2  /
    old   1: grant connect, resource to &USERNAME identified by &PASSWORD
    new   1: grant connect, resource to OTNTEST identified by OTNTEST
    Grant succeeded.
    SQL> grant create any directory, drop any directory to &USERNAME
      2  /
    old   1: grant create any directory, drop any directory to &USERNAME
    new   1: grant create any directory, drop any directory to OTNTEST
    Grant succeeded.
    SQL> grant alter session, create view to &USERNAME
      2  /
    old   1: grant alter session, create view to &USERNAME
    new   1: grant alter session, create view to OTNTEST
    Grant succeeded.
    SQL> alter user &USERNAME default tablespace &USER_TABLESPACE temporary tablespace &TEMP_TABLESPACE
      2  /
    old   1: alter user &USERNAME default tablespace &USER_TABLESPACE temporary tablespace &TEMP_TABLESPACE
    new   1: alter user OTNTEST default tablespace USERS temporary tablespace TEMP
    User altered.
    SQL> connect &USERNAME/&PASSWORD
    Connected.
    SQL> --
    SQL> alter session set events ='19027 trace name context forever, level 0x800'
      2  /
    Session altered.
    SQL> BEGIN
      2  DBMS_XMLSCHEMA.registerSchema(
      3  'chapter04prod.xsd',
      4  '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns="http://example.org/prod" targetNamespa
    fault="unqualified">
      5     <xsd:complexType name="ItemsType">
      6             <xsd:sequence>
      7                     <xsd:element name="product" type="ProductType"/>
      8             </xsd:sequence>
      9     </xsd:complexType>
    10     <xsd:complexType name="ProductType">
    11             <xsd:sequence>
    12                     <xsd:element name="num" type="xsd:integer"/>
    13                     <xsd:element name="name" type="xsd:string"/>
    14                     <xsd:element name="size" type="SizeType"/>
    15                     <xsd:element name="color" type="ColorType"/>
    16             </xsd:sequence>
    17     </xsd:complexType>
    18     <xsd:complexType name="SizeType">
    19             <xsd:simpleContent>
    20                     <xsd:extension base="xsd:integer">
    21                             <xsd:attribute name="system" type="xsd:string"/>
    22                     </xsd:extension>
    23             </xsd:simpleContent>
    24     </xsd:complexType>
    25     <xsd:complexType name="ColorType">
    26             <xsd:attribute name="value" type="xsd:string"/>
    27     </xsd:complexType>
    28  </xsd:schema>',
    29  TRUE, TRUE, FALSE, FALSE);
    30  END;
    31  /
    PL/SQL procedure successfully completed.
    SQL> BEGIN
      2  DBMS_XMLSCHEMA.registerSchema(
      3  'chapter04ord1.xsd',
      4  '<xsd:schema xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns
    ://example.org/prod" targetNamespace="http://example.org/ord" elementFormDefault="qualified">
      5     <xsd:import namespace="http://example.org/prod" schemaLocation="chapter04prod.xsd"/>
      6     <xsd:simpleType name="OrderNumType">
      7             <xsd:restriction base="xsd:string"/>
      8     </xsd:simpleType>
      9     <xsd:complexType name="InfoType" xdb:SQLType="INFO_TYPE_T"/>
    10     <xsd:complexType name="CustomerType">
    11             <xsd:all>
    12                     <xsd:element name="name" type="CustNameType"/>
    13                     <xsd:element name="num" type="xsd:integer"/>
    14                     <xsd:element name="info" type="InfoType" minOccurs="1" form="unqualified"/>
    15             </xsd:all>
    16     </xsd:complexType>
    17     <xsd:simpleType name="CustNameType">
    18             <xsd:restriction base="xsd:string"/>
    19     </xsd:simpleType>
    20     <xsd:element name="customers" type="CustomersType"/>
    21     <xsd:complexType name="CustomersType">
    22             <xsd:sequence>
    23                     <xsd:element name="customer" type="CustomerType" minOccurs="0" maxOccurs="unbounded"
    24             </xsd:sequence>
    25     </xsd:complexType>
    26     <xsd:element name="order" type="OrderType"/>
    27     <xsd:element name="customer" type="CustomerType"/>
    28     <xsd:complexType name="OrderType">
    29             <xsd:sequence>
    30                     <xsd:element name="num" type="OrderNumType"/>
    31                     <xsd:element name="customer" type="CustomerType" maxOccurs="unbounded"/>
    32                     <xsd:element name="items" type="prod:ItemsType"/>
    33             </xsd:sequence>
    34     </xsd:complexType>
    35  </xsd:schema>',
    36  TRUE, TRUE, FALSE, FALSE);
    37  END;
    38  /
    PL/SQL procedure successfully completed.
    SQL> BEGIN
      2  DBMS_XMLSCHEMA.registerSchema(
      3  'chapter04infozipcode.xsd',
      4  '<xsd:schema xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns
    //example.org/info/zipcode" targetNamespace="http://example.org/info/zipcode" elementFormDefault="unqualifie
      5     <xsd:import namespace="http://example.org/ord" schemaLocation="chapter04ord1.xsd"/>
      6     <xsd:complexType name="InfoType" xdb:SQLType="ZIPCODE_INFO_TYPE_T">
      7             <xsd:complexContent>
      8                     <xsd:extension base="ord:InfoType">
      9                             <xsd:sequence>
    10                                     <xsd:element name="zipcode" type="xsd:string"/>
    11                                     <xsd:element name="suffix" type="xsd:string"/>
    12                             </xsd:sequence>
    13                     </xsd:extension>
    14             </xsd:complexContent>
    15     </xsd:complexType>
    16  </xsd:schema>',
    17  TRUE, TRUE, FALSE, FALSE);
    18  END;
    19  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> BEGIN
      2  DBMS_XMLSCHEMA.registerSchema(
      3  'chapter04infostreet.xsd',
      4  '<xsd:schema xmlns:xdb="http://xmlns.oracle.com/xdb" xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns
    //example.org/info/street" targetNamespace="http://example.org/info/street" elementFormDefault="unqualified"
      5     <xsd:import namespace="http://example.org/ord" schemaLocation="chapter04ord1.xsd"/>
      6     <xsd:complexType name="InfoType" xdb:SQLType="STREET_INFO_TYPE_T">
      7             <xsd:complexContent>
      8                     <xsd:extension base="ord:InfoType">
      9                             <xsd:sequence>
    10                                     <xsd:element name="street" type="xsd:string"/>
    11                                     <xsd:element name="suffix" type="xsd:string"/>
    12                             </xsd:sequence>
    13                     </xsd:extension>
    14             </xsd:complexContent>
    15     </xsd:complexType>
    16  </xsd:schema>',
    17  TRUE, TRUE, FALSE, FALSE);
    18  END;
    19  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> BEGIN
      2  DBMS_XMLSCHEMA.registerSchema(
      3  'chapter04nonamespace.xsd',
      4  '<xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:ord="http://example.org/ord">
      5     <xsd:import namespace="http://example.org/ord" schemaLocation="chapter04ord1.xsd"/>
      6     <xsd:element name="info" type="ord:InfoType"/>
      7  </xsd:schema>',
      8  TRUE, TRUE, FALSE, FALSE);
      9  END;
    10  /
    PL/SQL procedure successfully completed.
    SQL>
    SQL> CREATE TABLE customer (
      2  name VARCHAR(64),
      3  num INTEGER,
      4  info XMLTYPE)
      5  XMLType info STORE AS OBJECT RELATIONAL
      6  XMLSCHEMA "chapter04nonamespace.xsd"
      7  ELEMENT "info";
    Table created.
    SQL>
    SQL> INSERT INTO customer (name, num, info)
      2  VALUES ('George Jones', 1,
      3  XMLType(
      4  '<info xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:zipcode="http://example.org/info/zip
      5     <zipcode>28877</zipcode>
      6     <suffix>s1</suffix>
      7  </info>'));
    1 row created.
    SQL>
    SQL> INSERT INTO customer (name, num, info)
      2  VALUES ('Jim Jones', 2,
      3  XMLType(
      4  '<info xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:street="http://example.org/info/stre
      5     <street>3456 Autumn Lane</street>
      6     <suffix>s2</suffix>
      7  </info>'));
    1 row created.
    SQL> /
    1 row created.
    SQL> SELECT name,
      2         extractValue(info, '/info/zipcode'),
      3         extractValue(info, '/info/street')
      4    FROM customer
      5  WHERE extractValue(info, '/info/zipcode/text()') LIKE '2%'
      6     OR extractValue(info, '/info/street/text()') LIKE '3456%';
    NAME
    EXTRACTVALUE(INFO,'/INFO/ZIPCODE')
    EXTRACTVALUE(INFO,'/INFO/STREET')
    George Jones
    28877
    Jim Jones
    3456 Autumn Lane
    NAME
    EXTRACTVALUE(INFO,'/INFO/ZIPCODE')
    EXTRACTVALUE(INFO,'/INFO/STREET')
    Jim Jones
    3456 Autumn Lane
    SQL>
    SQL> CREATE UNIQUE INDEX customer_infozipcode ON customer(
      2  extractValue
      3  (
      4    info,
      5    '/info[@xsi:type="zipcode:InfoType"]/zipcode',
      6    'xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
      7    xmlns:zipcode="http://example.org/info/zipcode"'
      8  ))
      9  /
    Index created.
    SQL> select column_name
      2    from user_ind_columns
      3   where INDEX_NAME = 'CUSTOMER_INFOZIPCODE'
      4  /
    COLUMN_NAME
    SYS_NC00014$
    SQL> select INDEX_NAME,COLUMN_EXPRESSION
      2    from user_ind_expressions
      3  /
    INDEX_NAME
    COLUMN_EXPRESSION
    CUSTOMER_INFOZIPCODE
    EXTRACTVALUE(SYS_MAKEXML('0341F05603124922B4F6F94DC5E30C2F',4870,"SYS_NC00004$",
    SQL> DROP INDEX CUSTOMER_INFOZIPCODE
      2  /
    Index dropped.
    SQL> desc INFO_TYPE_T
    INFO_TYPE_T is NOT FINAL
    Name                                      Null?    Type
    SYS_XDBPD$                                         XDB.XDB$RAW_LIST_T
    SQL> --
    SQL> desc ZIPCODE_INFO_TYPE_T
    ZIPCODE_INFO_TYPE_T extends OTNTEST.INFO_TYPE_T
    ZIPCODE_INFO_TYPE_T is NOT FINAL
    Name                                      Null?    Type
    SYS_XDBPD$                                         XDB.XDB$RAW_LIST_T
    zipcode                                            VARCHAR2(4000 CHAR)
    suffix                                             VARCHAR2(4000 CHAR)
    SQL> --
    SQL> desc STREET_INFO_TYPE_T
    STREET_INFO_TYPE_T extends OTNTEST.INFO_TYPE_T
    STREET_INFO_TYPE_T is NOT FINAL
    Name                                      Null?    Type
    SYS_XDBPD$                                         XDB.XDB$RAW_LIST_T
    street                                             VARCHAR2(4000 CHAR)
    suffix                                             VARCHAR2(4000 CHAR)
    SQL> --
    SQL> CREATE UNIQUE INDEX customer_infozipcode ON customer(TREAT(INFO.XMLDATA AS ZIPCODE_INFO_TYPE_T)."zipcod
      2  /
    Index created.
    SQL> select column_name
      2    from user_ind_columns
      3   where INDEX_NAME = 'CUSTOMER_INFOZIPCODE'
      4  /
    COLUMN_NAME
    TREAT("SYS_NC00007$" AS "ZIPCODE_INFO_TYPE_T")."zipcode"
    SQL> select INDEX_NAME,COLUMN_EXPRESSION
      2    from user_ind_expressions
      3  /
    no rows selected
    SQL> INSERT INTO customer (name, num, info)
      2  VALUES ('Jerry Jones', 3,
      3  XMLType(
      4  '<info xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:zipcode="http://example.org/info/zip
      5     <zipcode>28877</zipcode>
      6     <suffix>s1</suffix>
      7  </info>'))
      8  /
    INSERT INTO customer (name, num, info)
    ERROR at line 1:
    ORA-00001: unique constraint (OTNTEST.CUSTOMER_INFOZIPCODE) violated
    SQL> INSERT INTO customer (name, num, info)
      2  VALUES ('Jerry Jones', 3,
      3  XMLType(
      4  '<info xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:street="http://example.org/info/stre
      5     <street>3456 Autumn Lane</street>
      6     <suffix>s3</suffix>
      7  </info>'))
      8  /
    1 row created.
    SQL>In you solution a functional index was created. In my case, by breaking the XML abstraction, and using object-relational SQL to create the index (DDL statements are the one case where I feel this is acceptable) I was able to create a pure B-TREE index which has the same effect..

  • How to create index on XMLTYPE ordered collection table?

    I am using Oracle 11.2.0.2.
    Essentially, my XML documents have a 3-level hierarchy:
    event
      +---action  [1:n]
             +---- param   [1:n]
    I am trying to create indexes on ordered collection tables, but can not get the syntax right...
    I have created a table with an object-relational XMLType column:
    CREATE TABLE T_C_RMP_MNTRNG_XML_FULL_IL4 (
      MESSAGE_ID NUMBER(22,0) NOT NULL ENABLE,
      XML_EVAL_ID NUMBER(22,0),
      VIN7 VARCHAR2(7 BYTE),
      FLEET_ID VARCHAR2(50 BYTE),
      CSC_SW_VERSION VARCHAR2(100 BYTE),
      RECEIVED DATE,
      XML_CONTENT SYS.XMLTYPE ,
      DWH_LM_TS_UTC DATE NOT NULL ENABLE,
      CONSTRAINT PK_C_RMP_MNTRNG_XML_FULL_IL4 PRIMARY KEY (MESSAGE_ID)
    ) NOLOGGING TABLESPACE CATALOG
    VARRAY "XML_CONTENT"."XMLDATA"."action" STORE AS TABLE "T_OR_MON_ACTION" (
      NOLOGGING TABLESPACE "CATALOG"
      VARRAY "param" STORE AS TABLE "T_OR_MON_ACTION_PARAM" (
      NOLOGGING TABLESPACE "CATALOG"
      ) RETURN AS LOCATOR
    ) RETURN AS LOCATOR
    XMLTYPE XML_CONTENT STORE AS OBJECT RELATIONAL XMLSCHEMA "http://mydomain.com/cs.xsd" ELEMENT "monitoring";
    I am running the following SELECT:
    SELECT EVENT_ID, ACTION_SUB_ID, MESSAGE_ID, ACTION_TYPE, UNIXTS_TO_DATE(ACTION_TIMESTAMP) ACTION_TIMESTAMP
    FROM T_C_RMP_MNTRNG_XML_FULL_IL4,
    XMLTABLE(
      'for $i1 in /monitoring ,
      $i2 in $i1/action           
      return element r {             
      $i1/eventId,             
      $i2           
      PASSING XML_CONTENT COLUMNS
      EVENT_ID VARCHAR(40) PATH 'eventId',
      ACTION_SUB_ID INTEGER PATH 'action/actionSubId',
      ACTION_TYPE VARCHAR2(100) PATH 'action/type',
      ACTION_TIMESTAMP NUMBER(13,0) PATH 'action/time'
    ) T2
    WHERE (
      EVENT_ID IS NOT NULL AND ACTION_SUB_ID IS NOT NULL
    The explain plan looks like this (sorry, don't know how to get this formatted any "eye-friendlier"):
    | Id  | Operation          | Name                        | Rows  | Bytes |TempSpc| Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |                             |  1609K|  6316M|       |  6110K  (1)| 20:22:11 |
    |*  1 |  HASH JOIN         |                             |  1609K|  6316M|   111M|  6110K  (1)| 20:22:11 |
    |   2 |   TABLE ACCESS FULL| T_C_RMP_MNTRNG_XML_FULL_IL4 |   582K|   104M|       |  5241   (1)| 00:01:03 |
    |*  3 |   TABLE ACCESS FULL| T_OR_MON_ACTION             |    32M|   117G|       |   105K  (2)| 00:21:08 |
    Predicate Information (identified by operation id):
       1 - access("NESTED_TABLE_ID"="T_C_RMP_MNTRNG_XML_FULL_IL4"."SYS_NC0001300014$")
           filter(CAST(SYS_XQ_UPKXML2SQL(SYS_XQEXVAL(SYS_XQEXTRACT(XMLCONCAT(SYS_XMLGEN("T_C_RMP_MNTRN
                  G_XML_FULL_IL4"."SYS_NC00017$",NULL,SYS_XMLCONV("T_C_RMP_MNTRNG_XML_FULL_IL4"."SYS_NC00012$",0,32,
                  'EC1EEF23FD023A27E04032A06D930A8D',3,3783,1)),SYS_MAKEXML('EC1EEF23FD023A27E04032A06D930A8D',3780,
                  "T_C_RMP_MNTRNG_XML_FULL_IL4"."SYS_NC00008$","SYS_ALIAS_0"."SYS_NC_ROWINFO$")),'/eventId',NULL),0,
                  0,20971520,0),50,1,2) AS VARCHAR(40) ) IS NOT NULL)
       3 - filter(CAST(TO_NUMBER(TO_CHAR("SYS_ALIAS_0"."actionSubId")) AS INTEGER ) IS NOT NULL)
    Note
       - dynamic sampling used for this statement (level=2)
       - Unoptimized XML construct detected (enable XMLOptimizationCheck for more information)
    The XML schema looks like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <xs:schema xmlns:xs="http://www.w3.org/2001/XMLSchema" elementFormDefault="qualified" xmlns:oraxdb="http://xmlns.oracle.com/xdb" oraxdb:storeVarrayAsTable="true" oraxdb:flags="2105639" oraxdb:schemaURL="http://mydomain.com/cs.xsd" oraxdb:schemaOwner="MYUSER" oraxdb:numProps="23">
      <xs:element name="monitoring" oraxdb:propNumber="3785" oraxdb:global="true" oraxdb:SQLName="monitoring" oraxdb:SQLType="monitoring755_T" oraxdb:SQLSchema="MYUSER" oraxdb:memType="258" oraxdb:defaultTable="monitoring757_TAB" oraxdb:defaultTableSchema="MYUSER">
        <xs:complexType oraxdb:SQLType="monitoring755_T" oraxdb:SQLSchema="MYUSER">
          <xs:sequence>
            <xs:element maxOccurs="unbounded" ref="action" oraxdb:propNumber="3780" oraxdb:global="false" oraxdb:SQLName="action" oraxdb:SQLType="action752_T" oraxdb:SQLSchema="MYUSER" oraxdb:memType="258" oraxdb:MemInline="false" oraxdb:SQLInline="true" oraxdb:JavaInline="false" oraxdb:SQLCollType="action756_COLL" oraxdb:SQLCollSchema="MYUSER"/>
            <xs:element ref="reservationType" oraxdb:propNumber="3781" oraxdb:global="false" oraxdb:SQLName="reservationType" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:MemInline="false" oraxdb:SQLInline="true" oraxdb:JavaInline="false"/>
            <xs:element ref="softwareVersion" oraxdb:propNumber="3782" oraxdb:global="false" oraxdb:SQLName="softwareVersion" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:MemInline="false" oraxdb:SQLInline="true" oraxdb:JavaInline="false"/>
            <xs:element ref="eventId" oraxdb:propNumber="3783" oraxdb:global="false" oraxdb:SQLName="eventId" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:MemInline="false" oraxdb:SQLInline="true" oraxdb:JavaInline="false"/>
            <xs:element ref="vin" oraxdb:propNumber="3784" oraxdb:global="false" oraxdb:SQLName="vin" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:MemInline="false" oraxdb:SQLInline="true" oraxdb:JavaInline="false"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="action" oraxdb:propNumber="3790" oraxdb:global="true" oraxdb:SQLName="action" oraxdb:SQLType="action752_T" oraxdb:SQLSchema="MYUSER" oraxdb:memType="258" oraxdb:defaultTable="action754_TAB" oraxdb:defaultTableSchema="MYUSER">
        <xs:complexType oraxdb:SQLType="action752_T" oraxdb:SQLSchema="MYUSER">
          <xs:sequence>
            <xs:element ref="type" oraxdb:propNumber="3786" oraxdb:global="false" oraxdb:SQLName="type" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:MemInline="false" oraxdb:SQLInline="true" oraxdb:JavaInline="false"/>
            <xs:element maxOccurs="unbounded" ref="param" oraxdb:propNumber="3787" oraxdb:global="false" oraxdb:SQLName="param" oraxdb:SQLType="param749_T" oraxdb:SQLSchema="MYUSER" oraxdb:memType="258" oraxdb:MemInline="false" oraxdb:SQLInline="true" oraxdb:JavaInline="false" oraxdb:SQLCollType="param753_COLL" oraxdb:SQLCollSchema="MYUSER"/>
            <xs:element ref="actionSubId" oraxdb:propNumber="3788" oraxdb:global="false" oraxdb:SQLName="actionSubId" oraxdb:SQLType="NUMBER" oraxdb:memType="2" oraxdb:MemInline="false" oraxdb:SQLInline="true" oraxdb:JavaInline="false"/>
            <xs:element ref="time" oraxdb:propNumber="3789" oraxdb:global="false" oraxdb:SQLName="time" oraxdb:SQLType="NUMBER" oraxdb:memType="2" oraxdb:MemInline="false" oraxdb:SQLInline="true" oraxdb:JavaInline="false"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="type" type="xs:string" oraxdb:propNumber="3791" oraxdb:global="true" oraxdb:SQLName="type" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:defaultTable="type751_TAB" oraxdb:defaultTableSchema="MYUSER"/>
      <xs:element name="param" oraxdb:propNumber="3794" oraxdb:global="true" oraxdb:SQLName="param" oraxdb:SQLType="param749_T" oraxdb:SQLSchema="MYUSER" oraxdb:memType="258" oraxdb:defaultTable="param750_TAB" oraxdb:defaultTableSchema="MYUSER">
        <xs:complexType oraxdb:SQLType="param749_T" oraxdb:SQLSchema="MYUSER">
          <xs:sequence>
            <xs:element minOccurs="0" ref="value" oraxdb:propNumber="3792" oraxdb:global="false" oraxdb:SQLName="value" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:MemInline="false" oraxdb:SQLInline="true" oraxdb:JavaInline="false"/>
            <xs:element ref="key" oraxdb:propNumber="3793" oraxdb:global="false" oraxdb:SQLName="key" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:MemInline="false" oraxdb:SQLInline="true" oraxdb:JavaInline="false"/>
          </xs:sequence>
        </xs:complexType>
      </xs:element>
      <xs:element name="value" type="xs:string" oraxdb:propNumber="3795" oraxdb:global="true" oraxdb:SQLName="value" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:defaultTable="value748_TAB" oraxdb:defaultTableSchema="MYUSER"/>
      <xs:element name="key" type="xs:string" oraxdb:propNumber="3796" oraxdb:global="true" oraxdb:SQLName="key" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:defaultTable="key747_TAB" oraxdb:defaultTableSchema="MYUSER"/>
      <xs:element name="actionSubId" type="xs:integer" oraxdb:propNumber="3797" oraxdb:global="true" oraxdb:SQLName="actionSubId" oraxdb:SQLType="NUMBER" oraxdb:memType="2" oraxdb:defaultTable="actionSubId746_TAB" oraxdb:defaultTableSchema="MYUSER"/>
      <xs:element name="time" type="xs:integer" oraxdb:propNumber="3798" oraxdb:global="true" oraxdb:SQLName="time" oraxdb:SQLType="NUMBER" oraxdb:memType="2" oraxdb:defaultTable="time745_TAB" oraxdb:defaultTableSchema="MYUSER"/>
      <xs:element name="reservationType" type="xs:string" oraxdb:propNumber="3799" oraxdb:global="true" oraxdb:SQLName="reservationType" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:defaultTable="reservationType744_TAB" oraxdb:defaultTableSchema="MYUSER"/>
      <xs:element name="softwareVersion" type="xs:string" oraxdb:propNumber="3800" oraxdb:global="true" oraxdb:SQLName="softwareVersion" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:defaultTable="softwareVersion743_TAB" oraxdb:defaultTableSchema="MYUSER"/>
      <xs:element name="eventId" type="xs:string" oraxdb:propNumber="3801" oraxdb:global="true" oraxdb:SQLName="eventId" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:defaultTable="eventId742_TAB" oraxdb:defaultTableSchema="MYUSER"/>
      <xs:element name="vin" type="xs:string" oraxdb:propNumber="3802" oraxdb:global="true" oraxdb:SQLName="vin" oraxdb:SQLType="VARCHAR2" oraxdb:memType="1" oraxdb:defaultTable="vin741_TAB" oraxdb:defaultTableSchema="MYUSER"/>
    </xs:schema>
    How can I create an index on these ordered collection tables in order to improve performance?
    I found the example at http://docs.oracle.com/cd/E11882_01/appdev.112/e23094/xdb_rewrite.htm#ADXDB5859 but am not able to apply it to this particular case...
    Thank you in advance...

    If the schema is not annotated then xs:integer and xs:string are mapped to NUMBER and VARCHAR2(4000) datatypes, so you have to use those in your query in order to avoid unnecessary typecasting operations.
    You should also use chained XMLTABLEs when accessing a parent/child relationship instead of a FLWOR expression, otherwise the CBO may not rewrite the XQuery correctly (maybe it's fixed in the latest release).
    If you make those changes, the plan should show cleaner predicates :
    SQL> SELECT EVENT_ID, ACTION_SUB_ID, MESSAGE_ID, ACTION_TYPE, ACTION_TIMESTAMP
      2  FROM test_table,
      3  XMLTABLE('/monitoring'
      4    PASSING XML_CONTENT COLUMNS
      5      EVENT_ID         VARCHAR2(4000) PATH 'eventId',
      6      actions          XMLTYPE        PATH 'action'
      7    ) T1,
      8  XMLTABLE('/action'
      9    PASSING actions COLUMNS
    10      ACTION_SUB_ID    NUMBER PATH 'actionSubId',
    11      ACTION_TYPE      VARCHAR2(4000) PATH 'type',
    12      ACTION_TIMESTAMP NUMBER PATH 'time'
    13  ) T2
    14  WHERE EVENT_ID IS NOT NULL
    15  AND ACTION_SUB_ID IS NOT NULL
    16  ;
    Execution Plan
    Plan hash value: 1763884463
    | Id  | Operation                    | Name            | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT             |                 |   109 |   220K|     6  (17)| 00:00:01 |
    |   1 |  MERGE JOIN                  |                 |   109 |   220K|     6  (17)| 00:00:01 |
    |*  2 |   TABLE ACCESS BY INDEX ROWID| TEST_TABLE      |    11 |   352 |     2   (0)| 00:00:01 |
    |   3 |    INDEX FULL SCAN           | SYS_C007567     |    11 |       |     1   (0)| 00:00:01 |
    |*  4 |   SORT JOIN                  |                 |   109 |   216K|     4  (25)| 00:00:01 |
    |*  5 |    TABLE ACCESS FULL         | T_OR_MON_ACTION |   109 |   216K|     3   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - filter("TEST_TABLE"."SYS_NC00012$" IS NOT NULL)
       4 - access("SYS_ALIAS_0"."NESTED_TABLE_ID"="TEST_TABLE"."SYS_NC0000800009$")
           filter("SYS_ALIAS_0"."NESTED_TABLE_ID"="TEST_TABLE"."SYS_NC0000800009$")
       5 - filter("SYS_ALIAS_0"."actionSubId" IS NOT NULL)
    Note
       - dynamic sampling used for this statement (level=2)
    Now, if still necessary, it all boils down to choosing a technique to index NULL values :
    - composite index with a not null or constant column
    - FBI
    - bitmap
    Pick one that best fits your data, selectivity and activity on the tables.

  • How to create index on xmtype column

    Hi,
    I have a table as follows
    CREATE TABLE T_TEST_XML (PROCESS_ID NUMBER, TXT_XML XMLTYPE);
    I query the above table very frequently with the query
    SELECT * FROM T_TEST_XML TXS WHERE EXISTSNODE(TXS.TXT_XML, '/order[status="PEN"]') = 1
    How to create function based index on the TXT_XML column for the xpath expression /order[status="PEN"]' to improve the query performance?
    Thank you

    Actually if you are limited to using older software
    1. Consider defining an XML Schema and storing the XML using object relational storage.
    or
    2. If you must store the XML as CLOB create the index on extractValue(), rather than existsNode() and supply the predicate value at the SQL level rather than the XPATH level.
    SQL> DROP TABLE T_TEST_XML
      2  /
    Table dropped.
    SQL> CREATE TABLE T_TEST_XML (PROCESS_ID NUMBER, TXT_XML XMLTYPE)
      2  /
    Table created.
    SQL> create INDEX T_TEXT_XML_IDX on T_TEST_XML( extractValue(TXT_XML,'/order/status'))
      2  /
    Index created.
    SQL> set autotrace on explain
    SQL> --
    SQL> SELECT *
      2    FROM T_TEST_XML TXS
      3   WHERE ExistsNode(TXT_XML,'/order[status="PEN"]') = 1
      4  /
    no rows selected
    Execution Plan
    Plan hash value: 3001212210
    | Id  | Operation          | Name       | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT   |            |     1 |  2017 |    31   (0)| 00:00:01 |
    |   1 |  NESTED LOOPS SEMI |            |     1 |  2017 |    31   (0)| 00:00:01 |
    |   2 |   TABLE ACCESS FULL| T_TEST_XML |     1 |  2015 |     2   (0)| 00:00:01 |
    |*  3 |   XPATH EVALUATION |            |       |       |            |          |
    Predicate Information (identified by operation id):
       3 - filter("P"."C_01$"='PEN')
    Note
       - dynamic sampling used for this statement (level=2)
    SQL> SELECT *
      2    FROM T_TEST_XML TXS
      3   WHERE extractValue(TXT_XML,'/order/status') = 'PEN'
      4  /
    no rows selected
    Execution Plan
    Plan hash value: 1430727070
    | Id  | Operation                   | Name           | Rows  | Bytes | Cost (%CPU)| Time     |
    |   0 | SELECT STATEMENT            |                |     1 |  2015 |     1   (0)| 00:00:01 |
    |   1 |  TABLE ACCESS BY INDEX ROWID| T_TEST_XML     |     1 |  2015 |     1   (0)| 00:00:01 |
    |*  2 |   INDEX RANGE SCAN          | T_TEXT_XML_IDX |     1 |       |     1   (0)| 00:00:01 |
    Predicate Information (identified by operation id):
       2 - access(EXTRACTVALUE(SYS_MAKEXML(0,"SYS_NC00003$"),'/order/status',null,0,0,5242
                  93,133120)='PEN')
    Note
       - dynamic sampling used for this statement (level=2)
    SQL>
    SQL>
    SQL>
    SQL>
    SQL>
    SQL>This allows the index to support querying on any value of status, rather than just PEN

  • How to create  index for a column of a view

    Hi,
    I have created view for a table and then i am trying to create index for a column of that view. i am using the query "CREATE INDEX index_name ON view_name (col)". but Mysql is showing error like "view_name is not a base table".
    How can i do that......

    As mentioned this is a java forum not a mysql forum, but as I know the answer - you can't create an index directly on a view in mysql.

  • How to create index on a single parition

    Hi,
    I have a table which has got 7 partitons,I want to index only one partition how do it?
    i am using oracle 11g.Also i want to know if it is possible to create an index within a o partiotn only fr some values..
    Edited by: user8731258 on Jul 13, 2012 12:35 AM

    Hi,
    I've been thinking a bit about your requirement.
    One way could be to use the fact that index do not "store" nulls.
    Let's make a table with data :SQL> create table t
      2  (
      3  grp integer,
      4  id integer,
      5  val varchar2(10)
      6  )
      7  partition by range(grp)
      8  (
      9  partition p01 values less than (2)
    10  ,partition p02 values less than (3)
    11  ,partition p03 values less than (4)
    12  ,partition pXX values less than (maxvalue)
    13  );
    Table created.
    SQL> insert into t select 1+mod(level,4), level, dbms_random.string('a',10) from dual connect by level <= 200000;
    200000 rows created.
    SQL> select grp, count(*) cnt from t group by grp order by grp;
           GRP       CNT
          1     50000
          2     50000
          3     50000
          4     50000
    SQL> select grp, count(*) cnt from t group by grp order by grp;
           GRP       CNT
          1     50000
          2     50000
          3     50000
          4     50000
    SQL> begin
      2  dbms_stats.gather_table_stats(
      3  ownname => user,
      4  tabname => 'T',
      5  method_opt => 'for all columns size 1',
      6  granularity => 'global and partition',
      7  estimate_percent => null);
      8  end;
      9  /
    PL/SQL procedure successfully completed.
    SQL> select table_name, partition_name, num_rows from user_tab_partitions where table_name='T' order by partition_name;
    TABLE_NAME                 PARTITION_NAME               NUM_ROWS
    T                      P01                       50000
    T                      P02                       50000
    T                      P03                       50000
    T                      PXX                       50000Now let's say you only want to index P01.
    You could do it as follows :SQL> create index t_idx on t(decode(grp,1,id,null)) local;
    Index created.The index would only have IDs from partition P01.
    SQL> select INDEX_NAME, PARTITION_NAME, DISTINCT_KEYS
      2  from user_ind_partitions
      3  where index_name='T_IDX'
      4  order by partition_name;
    INDEX_NAME                 PARTITION_NAME                DISTINCT_KEYS
    T_IDX                      P01                          50000
    T_IDX                      P02                           0
    T_IDX                      P03                           0
    T_IDX                      PXX                           0
    SQL> select SEGMENT_NAME, PARTITION_NAME, BYTES
      2  from user_segments
      3  where SEGMENT_NAME='T_IDX'
      4  order by partition_name;
    SEGMENT_NAME                                               PARTITION_NAME                BYTES
    T_IDX                                                    P01                        1048576
    T_IDX                                                    P02                          65536
    T_IDX                                                    P03                          65536
    T_IDX                                                    PXX                          65536See, only the keys from P01 are here, and only the segment for P01 partition has grown <i>(the 65k segment for the others partitions come from default values of storage clause which I didn't specify)</i>.
    Now you can query your table in the following way.
    Instead of writing (for P01) : select * from t where grp=1 and id between 30 and 40;If you want to use the index on P01, you would do :SQL> select * from t where grp=1 and decode(grp,1,id,null) between 30 and 40;
           GRP        ID VAL
          1        32 hSrmmTYXXW
          1        36 xofKlsxORE
          1        40 vazRGnWzWc
    Execution Plan
    Plan hash value: 1186642050
    | Id  | Operation                  | Name  | Rows  | Bytes | Cost (%CPU)| Time        | Pstart| Pstop |
    |   0 | SELECT STATEMENT             |        |   125 |  2375 |      3   (0)| 00:00:01 |        |        |
    |   1 |  PARTITION RANGE SINGLE         |        |   125 |  2375 |      3   (0)| 00:00:01 |      1 |      1 |
    |*  2 |   TABLE ACCESS BY LOCAL INDEX ROWID| T        |   125 |  2375 |      3   (0)| 00:00:01 |      1 |      1 |
    |*  3 |    INDEX RANGE SCAN             | T_IDX |   225 |        |      2   (0)| 00:00:01 |      1 |      1 |
    Predicate Information (identified by operation id):
       2 - filter("GRP"=1)
       3 - access(DECODE("GRP",1,"ID",NULL)>=30 AND DECODE("GRP",1,"ID",NULL)<=40)The index is being used.
    +(also note that the grp value is "given" twice in the query : once explicitly, the other one within the decode.)+
    Now for a query like : SQL> select * from t where grp=2 and id between 30 and 40;
           GRP        ID VAL
          2        33 bhFrCYCiDb
          2        37 jnPauHJiyo
    Execution Plan
    Plan hash value: 2931986080
    | Id  | Operation            | Name | Rows  | Bytes | Cost (%CPU)| Time     | Pstart| Pstop |
    |   0 | SELECT STATEMENT       |      |     5 |    95 |    68     (0)| 00:00:01 |       |       |
    |   1 |  PARTITION RANGE SINGLE|      |     5 |    95 |    68     (0)| 00:00:01 |     2 |     2 |
    |*  2 |   TABLE ACCESS FULL    | T    |     5 |    95 |    68     (0)| 00:00:01 |     2 |     2 |
    Predicate Information (identified by operation id):
       2 - filter("ID"<=40 AND "ID">=30 AND "GRP"=2)The optimizer goes for a FULL TABLE (partition) SCAN.
    <b>NOTE :</b> That would also work with a global index.
    Of course, it remains a rather dirty tweak...
    ;-)

  • I want information in practical sceario  how to create indexes?

    hi,
    i want complete information about indexes? how create indexes in real time?

    " Secondary Database
    First it must be stated that table design is a more logical work while index design is rather technical. In table design it might make sense to place certain fields (client, company code, ...) in the beginning. In index design, this is not advisable.  Very important for an index is that it contains very selective fields in the beginning. Those are fields like object numbers. Not selective are client, company code, ... 
    Indexes should be small (few fields).  The Database optimizer can combine two or more indexes to execute a query. 
    Indexes of one table should be disjoint (have few common fields), in order not to confuse the optimizer which index to use. 
    Note that each index slows the inserts into the table down. Updates are only slowed down if indexed fields are updated. In general, heavy inserted tables should have only few indexes while heavy selected tables might have more. 
    " Creating Secondary Indexes
    Procedure
    1.In the maintenance screen of the table, choose Indexes.
    If indexes already exist on the table, a list of these indexes is displayed. Choose .
    2.In the next dialog box, enter the index ID and choose 
    The maintenance screen for indexes appears.
    3.Enter an explanatory text in the field Short text.
    You can then use the short text to find the index at a later time, for example with the R/3 Repository Information System.
    4.Select the table fields to be included in the index using the input help for the Field name column.
    The order of the fields in the index is very important. See What to Keep in Mind for Secondary Indexes.
    5.If the values in the index fields already uniquely identify each record of the table, select Unique index.
    A unique index is always created in the database at activation because it also has a functional meaning (prevents double entries of the index fields).
    6.If it is not a unique index, leave Non-unique index selected.
    In this case you can use the radio buttons to define whether the index should be created for all database systems, for selected database systems or not at all in the database.
    7.Select for selected database systems if the index should only be created for selected database systems.
    Click on the arrow behind the radio buttons. A dialog box appears in which you can define up to 4 database systems with the input help. Select Selection list if the index should only be created on the given database systems. Select Exclusion list if the index should not be created on the given database systems. Choose .
    8.Choose  activate.
    " Result
    The secondary index is automatically created in the database during activation if the corresponding table was already created there and index creation was not excluded for the database system.
    You can find information about the activation flow in the activation log, which you can call with Utilities ® Activation log. If errors occurred when activating the index, the activation log is automatically displayed.
    " How to Check if an Index is Used
    Procedure
    1.Open a second session and choose System -> Utilities ->Performance trace.
    The Trace Requests screen appears.
    2.Select Trace on.
    The SQL trace is activated for your user, that is all the database operations under your user are recorded.
    3.In the first window, perform the action in which the index should be used.
    If your database system uses a cost-based optimizer, you should perform this action with as representative data as possible. A cost-based optimizer tries to determine the best index based on the statistics.
    4.In the second session, choose Trace off and then Trace list.
    Result
    The format of the generated output depends on the database system used. You can determine the index that the database used for your action with the EXPLAIN function for the critical statements (PREPARE, OPEN, REPOPEN).
    " What to Keep in Mind for Secondary Indexes
    How well an existing index supports data selection from a table largely depends on whether the data selected with the index represents the data that will ultimately be selected. This can best be shown using an example.
    ' Example  :
    An index is defined on fields FIELD1, FIELD2, FIELD3 and FIELD4 of table BSPTAB in this order. This table is accessed with the SELECT statement:
    SELECT * FROM BSPTAB WHERE FIELD1 = X1 AND FIELD2 = X2 AND FIELD4= X4.
    Since FIELD3 is not specified more exactly, only the index sorting up to FIELD2 is of any use. If the database system accesses the data using this index, it will quickly find all the records for which FIELD1 = X1 and FIELD2 = X2. You then have to select all the records for which FIELD4 = X4 from this set.
    The order of the fields in the index is very important for the accessing speed. The first fields should be those which have constant values for a large number of selections. During selection, an index is only of use up to the first unspecified field.
    Only those fields that significantly restrict the set of results in a selection make sense for an index.
    Reward  points if it is usefull.....
    Girish

  • DirectToXMLTypeMapping "create-tables" not generating XMLTYPE column type

    Can someone tell me how to code an XMLTYPE field such that "create-tables" will generate the XMLTYPE column and such that the IntegrityChecker will not throw an error.
    I am forced to run these alters after "create-tables" is run.
    ALTER TABLE XML_SYS_MSG drop column message;
    ALTER TABLE XML_SYS_MSG add (message XMLType);
    Snippets:
    <persistence...
    <property name="eclipselink.ddl-generation" value="create-tables" />
    </persistence>
    public class XmlMessageCustomizer implements DescriptorCustomizer {
    @Override
    public void customize(final ClassDescriptor descriptor) throws Exception {
    final DirectToXMLTypeMapping mapping = new DirectToXMLTypeMapping();
    descriptor.removeMappingForAttributeName("message");
    // name of the attribute
    mapping.setAttributeName("message");
    // IntegrityChecker requires uppercase for oracle
    // name of the column
    mapping.setFieldName("MESSAGE");
    descriptor.addMapping(mapping);
    @Entity(name = "XmlMessage")
    @Table(name = "XML_MSG")
    @Customizer(XmlMessageCustomizer.class)
    public class XmlMessage {
    @Id
    @GeneratedValue(strategy = GenerationType.AUTO)
    @Column(name = "ID")
    private long id;
    // @Column(columnDefinition = "XMLTYPE")
    // private String message;
    // ALTER TABLE XML_SYS_MSG drop column message;
    // ALTER TABLE XML_SYS_MSG add (message XMLType);
    private Document message;
    public XmlMessage() {
    public long getId() {
    return id;
    public void setId(final long id) {
    this.id = id;
    public Document getMessage() {
    return message;
    public void setMessage(final Document message) {
    this.message = message;
    Secondly if I turn on the IntegrityChecker it will fail
    public class EnableIntegrityChecker implements SessionCustomizer {
    @Override
    public void customize(final Session session) throws Exception {
    session.getIntegrityChecker().checkDatabase();
    session.getIntegrityChecker().setShouldCatchExceptions(false);
    }

    Adding:
         mapping.getField().setColumnDefinition("XMLTYPE");to the customizer should solve the problem.
    --Shaun                                                                                                                                                                                                                                                                                       

Maybe you are looking for

  • R/3: Cause of generated, but still inconsistent profile?

    Hi all, Does anyone know how you can create the following situation: I have a role with profile status "generated" (both SUPC & PFCG show green light). Yet in UST12 I find objects for that profile that are not in AGR_1251 or PFCG. SUIM confirms that

  • Oracle 11g certification in Developer track

    I would like to go for Oracle 11g certification in Developer track. I've already given 1Z0-051 paper. Is OCA 11g certification in Developer track now available. And if it is not currently available, I believe when it is going to be released the first

  • How can I find movies with subtitles from iTunes for iPad?

    The problems are two: 1) Using an iPad, can I find subtitled only movies? If were possible, how? 2) Ever with an iPad, it's possible setting on/off subtitles in movie? If were possible, how? Thanks, Cristiano.

  • Thinking about getting an Iphone 3g

    Hey guys, just have a couple questions concerning the iphone 3g Thinking about getting, two questions? I've heard some negative press about the actual phone feature ironically. Has the call drop issue been resolved, or is that issue mainly due to you

  • How to gzip a file using java

    Friends, I want to gzip a file in unix using my java program, can I use Runtime.exec() method and run the gzip command to achieve this ? Is there any other way to zip/compress a file using java api ? Thanks