Extractvalue, extract, xmlsequence

Could someone explain what extractvalue, xmlsequence and extract is doing in the following query:
select
   extractvalue(value(a),'Notebook/@Brand') As Brand
  ,extractvalue(value(a),'Notebook/@Model') As Model
from prod_xml_tab b,
table( xmlsequence( extract( demo_field,'Product/Notebook' ) ) ) a
where demo_field is not null;I went through documentation and still don't get it, and need some basic explanation step by step. for example, what is actually EXTRACT returning for first and second row?
the code for table and data is as follows:
create table prod_xml_tab (demo_field xmltype);
insert into prod_xml_tab values('
  <Product type="Laptop">
              <Notebook Brand="HP" Model="Pavilion dv6-3132TX Notebook">
                          <Harddisk>640 GB</Harddisk>
                          <Processor>Intel Core i7</Processor>
                          <RAM>4 GB</RAM>
                          <Price>1189</Price>
                          <Display Type="LED" MonitorSize="15.6"/>
                          <Weight>4.14</Weight>
              </Notebook>
              <Notebook Brand="HP" Model="HP Pavilion dv6-3032TX Notebook">
                          <Harddisk>640 GB</Harddisk>
                          <Processor>Intel Core i7</Processor>
                          <RAM>6 GB</RAM>
                          <Price>1104</Price>
                          <Display Type="LED" MonitorSize="15.6"/>
                          <Weight>4.1</Weight>
              </Notebook>
              <Notebook Brand="HP" Model="Pavilion dv6-3079TX Notebook">
                          <Harddisk>500 GB</Harddisk>
                          <Processor>Intel Core i7</Processor>
                          <RAM>4 GB</RAM>
                          <Price>1099</Price>
                          <Display Type="LED" MonitorSize="15.6"/>
                          <Weight>4.14</Weight>
              </Notebook>
</Product>');
insert into prod_xml_tab values('
<Product>
              <Notebook Brand="Toshiba" Model="Satellite A660/07R 3D Notebook">
                          <Harddisk>640 GB</Harddisk>
                          <Processor>Intel Core i7</Processor>
                          <RAM>4 GB</RAM>
                          <Price>1444</Price>
                          <Display Type="LED" MonitorSize="15.6"/>
                          <Weight>4.88</Weight>
              </Notebook>
</Product>');

943276 wrote:
thank you... this is a bit confusing when trying to reproduce excellent example on wrong version.
anyway, do you know what is this (+) doing formally? is this a notation similar to left outer join? I noticed it in some other example which I cannot find now.It is an outer join.
Example:
SQL> ed
Wrote file afiedt.buf
  1  WITH xml_table AS
  2      (SELECT xmltype('
  3      <root>
  4        <child name="name1">
  5          <grandchild name="name11">
  6            <greatgrandchild name="name111"/>
  7            <greatgrandchild name="name112"/>
  8          </grandchild>
  9          <grandchild name="name12"/>
10       </child>
11       <child name="name2">
12         <grandchild name="name21">
13            <greatgrandchild name="name211"/>
14         </grandchild>
15         <grandchild name="name22"/>
16       </child>
17     </root>') object_value FROM dual)
18  select po.child_name, gc.gchild_name, ggc.ggchild_name
19  from   xml_table p
20        ,xmltable('/root/child'
21                  passing p.object_value
22                  columns child_name  varchar2(100) path '@name'
23                         ,gchild      xmltype       path 'grandchild'
24                 ) po
25        ,xmltable('/grandchild'
26                  passing po.gchild
27                  columns gchild_name varchar2(100) path '@name'
28                         ,ggchild     xmltype       path 'greatgrandchild'
29                 ) (+) gc
30        ,xmltable('/greatgrandchild'
31                  passing gc.ggchild
32                  columns ggchild_name varchar2(100) path '@name'
33*               ) (+) ggc
SQL> /
CHILD_NAME GCHILD_NAME GGCHILD_NAME
name1      name11      name111
name1      name11      name112
name1      name12
name2      name21      name211
name2      name22without the outer joins it would just give...
SQL> ed
Wrote file afiedt.buf
  1  WITH xml_table AS
  2      (SELECT xmltype('
  3      <root>
  4        <child name="name1">
  5          <grandchild name="name11">
  6            <greatgrandchild name="name111"/>
  7            <greatgrandchild name="name112"/>
  8          </grandchild>
  9          <grandchild name="name12"/>
10       </child>
11       <child name="name2">
12         <grandchild name="name21">
13            <greatgrandchild name="name211"/>
14         </grandchild>
15         <grandchild name="name22"/>
16       </child>
17     </root>') object_value FROM dual)
18  select po.child_name, gc.gchild_name, ggc.ggchild_name
19  from   xml_table p
20        ,xmltable('/root/child'
21                  passing p.object_value
22                  columns child_name  varchar2(100) path '@name'
23                         ,gchild      xmltype       path 'grandchild'
24                 ) po
25        ,xmltable('/grandchild'
26                  passing po.gchild
27                  columns gchild_name varchar2(100) path '@name'
28                         ,ggchild     xmltype       path 'greatgrandchild'
29                 ) gc
30        ,xmltable('/greatgrandchild'
31                  passing gc.ggchild
32                  columns ggchild_name varchar2(100) path '@name'
33*               ) ggc
SQL> /
CHILD_NAME GCHILD_NAME GGCHILD_NAME
name1      name11      name111
name1      name11      name112
name2      name21      name211

Similar Messages

  • Oracle SQL - Extracting clob value from XML with repeating nodes

    Hi All,
    I am attempting to run SQL on a table (called test_xml with a column xml_data [data type xmltype]). The column contains xml with repeating nodes (description). The following statement runs successfully when the node contains data of a non clob size:
    SELECT
    extractvalue (Value (wl), '*/description')
    FROM test_xml
    , TABLE (xmlsequence (extract (xml_data, '*/record'))) wl
    but fails when description node contains a lot of data:
    ORA-01706: user function result value was too large
    I amended my query:
    SELECT
    extractvalue(Value (wl), '*/description').getClobVal()
    FROM test_xml
    , TABLE (xmlsequence (extract (xml_data, '*/record'))) wl
    but this fails with:
    ORA-22806: not an object or REF
    Thanks in Advance

    Hi Greg,
    11.2.0.2.0 (Although I will need to do this on my work instance also which is 10.2.0.4)That's gonna be a problem...
    Direct CLOB projection is supported starting with 11.2.0.2, using XMLTable or XMLCast/XQuery functions (extractvalue, extract, xmlsequence are deprecated now) :
    SELECT x.*
    FROM test_xml t
       , XMLTable(
           '/*/record'
           passing t.xml_data
           columns
             description  clob path 'description'
         ) x
    ;On prior versions, implicit conversions will occur to VARCHAR2 datatype, hence the limitation observed.
    AFAIK you have two options on 10.2.0.4 :
    1) Using Object-Relational storage, with the xdb:SQLType="CLOB" annotation.
    2) Using the following trick :
    SELECT dbms_xmlgen.convert(x.description.getClobVal(), 1) as description
    FROM test_xml t
       , XMLTable(
           '/*/record'
           passing t.xml_data
           columns
             description  xmltype path 'description/text()'
         ) x
    ;

  • XML file too large or XML element too large

    I am attempting to import an xml file into the repository and have it shred into the object-relational tables. I registered a schema and it created object-relational xml_tables, triggers, and types. The full xml file is > 80MB. XDB created all the fields as VARCHAR2(4000).
    error code when importing the full XML file. This is what I need to ultimately fix.
    DECLARE
      res BOOLEAN;
    BEGIN
      res := DBMS_XDB.createResource('/home/pharma/drugbank.xml',
                    bfilename('XMLPHARMA', 'drugbank.xml'),
                    nls_charset_id('AL32UTF8'));
    END;
    COMMIT;
    XML file encounters errors on the import.
    An error was encountered performing the requested operation
    ORA-30951: Element or attribute at Xpath references exceeds maximum length
    ORA-06512 at "XDB.DBMS_XDB", line 315
    ORA-06512 at line 4
    30951.00000 - "Element or attribute at Xpath %x exceeds maximum length"
    *Cause: An attempt was made to insert a node of length exceeding the maximum length (specified by the maxLength facet) into an XML document.
    *Action: Do not attempt to add a node exceeding the maximum length to XML documents.
    Vendor code 30951Error at Line:18I would guess that some of the fields have max lengths > 4000. I plan to annotate the schema with SQLType="CLOB", but need to know which fields to change. I was able to copy the xml file and reduce that xml file to one record, which imported into the tables. My plan was to write a view over the bfile to get the lengths of certain fields, annotate the .xsd with CLOBS where needed, and then import again. In order to do that, I have a 1 record file imported into a table and as a bfile.
    Here is my code selecting length from a generated object-relational table of only one record.
    CREATE OR REPLACE VIEW pharma.drugs_vw AS
    SELECT d.*
    FROM drugs, XMLTABLE
      ('/drugs' PASSING OBJECT_VALUE COLUMNS
        drugbank_id        VARCHAR2(20)   PATH 'drug/drugbank-id',
        name               VARCHAR2(50)   PATH 'drug/name',
        description        VARCHAR2(4000) PATH 'drug/description'   
      ) d
    select max(length(drugbank_id)) as dbidlen,
          max(length(name)) as nmlen,
          max(length(description)) as desclen
    from drugs_vw;
            DBIDLEN           NMLEN         DESCLEN
                  7               9             229
    1 row selected.Here is the code for the bfile. Same results, but using deprecated functions. I read the whitepaper, Oracle XML DB: Best practices to get optimal performance out of XML Queries. It says that extract(), extractvalue(), Table(XMLSequence()), and XMLType() are deprecated in 11gr2.
    -- Note extractvalue is deprecated in 11gr2 replaced by W3C standard
    --                                          XMLCast(XMLQuery())
    -- TABLE(XMLSequence) is replaced by XMLTable
    -- XMLType() is replaced by XMLParse()
    SELECT max(length(extractvalue(column_value, '/drug/drugbank-id'))) dbidlen,
           max(length(extractvalue(column_value, '/drug/name'))) nmlen,
           max(length(extractvalue(column_value, '/drug/description'))) desclen
    FROM TABLE(XMLSequence(XMLTYPE(bfilename('XMLPHARMA',
    'db00001.xml'),nls_charset_id('AL32UTF8')).extract('/drugs/drug'))) d
    WHERE ROWNUM <= 5;
            DBIDLEN           NMLEN         DESCLEN
                  7               9             229Is this better code for getting the maximum length of xml fields from a bfile? Here is what I have so far. This works on a single drugbank-id.
    SELECT max(length(drugbank_id)) AS dbidlen,
           max(length(name)) AS nmlen,
           max(length(description)) AS desclen
    FROM (XMLTABLE('*'
                    PASSING (XMLType(bfilename('XMLPHARMA', 'db00001.xml'),nls_charset_id('AL32UTF8')))
                    COLUMNS
        drugbank_id        VARCHAR2(20)   PATH 'drug/drugbank-id',
        name               VARCHAR2(50)   PATH 'drug/name',
        description        VARCHAR2(4000) PATH 'drug/description'
    );I try to run it on the full file and get this error
    Error report:
    SQL Error: ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00007: unexpected end-of-file encountered
    31011. 00000 -  "XML parsing failed"
    *Cause:    XML parser returned an error while trying to parse the document.
    *Action:   Check if the document to be parsed is valid.The code to create schema and object-relational tables. This worked fine.
    set serveroutput on
    -- Create resource file for schema
    DECLARE
      res BOOLEAN;
    BEGIN
      res := DBMS_XDB.createResource('/home/pharma/drugbank.xsd',
                    bfilename('XMLPHARMA', 'drugbank.xsd'),
                    nls_charset_id('AL32UTF8'));
      COMMIT;
    END;
    -- optional debugging of create types and tables if you want a trace
    ALTER SESSION SET EVENTS = '31098 TRACE NAME CONTEXT FOREVER';
    BEGIN
      DBMS_XMLSCHEMA.registerSchema(
          SCHEMAURL => 'http://localhost:8080/home/pharma/drugbank.xsd',
          SCHEMADOC => bfilename('XMLPHARMA', 'drugbank.xsd'),
          CSID      => nls_charset_id('AL32UTF8'),
          LOCAL     => TRUE,
          GENTYPES  => TRUE,
          GENTABLES => TRUE,
          OWNER     => 'PHARMA');
      COMMIT;
    END;
    SQL> select * from v$version;
    BANNER
    Oracle Database 11g Release 11.2.0.2.0 - Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE    11.2.0.2.0      Production
    TNS for 32-bit Windows: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - ProductionThe xml schema follows. Sorry about the length, but I think I might break something if I snipped it.
    <?xml version="1.0" encoding="UTF-8"?>
         <xs:schema 
         xmlns:xs="http://www.w3.org/2001/XMLSchema" 
         xmlns:xdb="http://xmlns.oracle.com/xdb"
         >
         <!-- General type definitions -->
         <xs:simpleType name="DecimalOrEmptyType">
              <xs:union memberTypes="xs:decimal EmptyStringType"/>
         </xs:simpleType>
         <xs:simpleType name="EmptyStringType">
              <xs:restriction base="xs:string">
                   <xs:enumeration value=""/>
              </xs:restriction>
         </xs:simpleType>
         <!-- Element Definitions -->
         <!-- Drug secondary accession number definition begins -->
         <xs:element name="secondary-accession-numbers" xdb:defaultTable="SECONDARY_ACCESSION_NUMBERS">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element name="secondary-accession-number" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug secondary accession number definition ends -->
         <!-- Drug groups definition begins -->
         <xs:element name="groups" xdb:defaultTable="GROUPS">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element name="group">
                             <xs:simpleType>
                                  <xs:restriction base="xs:string">
                                       <xs:enumeration value="approved"/>
                                       <xs:enumeration value="illicit"/>
                                       <xs:enumeration value="experimental"/>
                                       <xs:enumeration value="withdrawn"/>
                                       <xs:enumeration value="nutraceutical"/>
                                  </xs:restriction>
                             </xs:simpleType>
                        </xs:element>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug groups definition ends -->
         <!-- Drug taxonomy definition begins -->
         <xs:element name="substructure">
              <xs:complexType>
                   <xs:simpleContent>
                        <xs:extension base="xs:string">
                             <xs:attribute name="class" type="xs:string" use="required"/>
                        </xs:extension>
                   </xs:simpleContent>
              </xs:complexType>
         </xs:element>
         <xs:element name="substructures" xdb:defaultTable="SUBSTRUCTURES">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element ref="substructure"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:element name="taxonomy" xdb:defaultTable="TAXONOMY">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="kingdom" type="xs:string"/>
                        <xs:element ref="substructures"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug taxonomy definition ends -->
         <!-- Drug brands definition begins -->
         <xs:element name="brands" xdb:defaultTable="BRANDS">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element name="brand" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug brands definition ends -->
         <!-- Drug mixtures definition begins -->
         <xs:element name="mixture">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="name" type="xs:string"/>
                        <xs:element name="ingredients" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:element name="mixtures" xdb:defaultTable="MIXTURES">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element ref="mixture"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug mixtures definition ends -->
         <!-- Drug packagers definition begins -->
         <xs:element name="packager">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="name" type="xs:string"/>
                        <xs:element name="url" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:element name="packagers" xdb:defaultTable="PACKAGERS">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element ref="packager"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug packagers definition ends -->
         <!-- Drug manufacturers definition begins -->
         <xs:element name="manufacturer">
              <xs:complexType>
                   <xs:simpleContent>
                        <xs:extension base="xs:string">
                             <xs:attribute name="generic" type="xs:string" use="required"/>
                        </xs:extension>
                   </xs:simpleContent>
              </xs:complexType>
         </xs:element>
         <xs:element name="manufacturers" xdb:defaultTable="MANUFACTURERS">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element ref="manufacturer"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug manufactures definition ends -->
         <!-- Drug pricing definition begins -->
         <xs:element name="cost">
              <xs:complexType>
                   <xs:simpleContent>
                        <xs:extension base="xs:string">
                             <xs:attribute name="currency" type="xs:string" use="required"/>
                        </xs:extension>
                   </xs:simpleContent>
              </xs:complexType>
         </xs:element>
         <xs:element name="price">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="description" type="xs:string"/>
                        <xs:element ref="cost"/>
                        <xs:element name="unit" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:element name="prices" xdb:defaultTable="PRICES">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element ref="price"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug pricing definition ends -->
         <!-- Drug categories definition begins -->
         <xs:element name="categories" xdb:defaultTable="CATEGORIES">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element name="category" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug categories definition ends -->
         <!-- Drug affected orgainsms definition begins -->
         <xs:element name="affected-organisms" xdb:defaultTable="AFFECTED_ORGANISMS">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element name="affected-organism" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug affected organisms definition ends -->
         <!-- Drug dosage definition begins -->
         <xs:element name="dosage">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="form" type="xs:string"/>
                        <xs:element name="route" type="xs:string"/>
                        <xs:element name="strength" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:element name="dosages" xdb:defaultTable="DOSAGES">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element ref="dosage"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug dosages definition ends -->
         <!-- Drug ATC codes definition begins -->
         <xs:element name="atc-codes" xdb:defaultTable="ATC_CODES">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element name="atc-code" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug ATC codes definition ends -->
         <!-- Drug AHFS codes definition begins -->
         <xs:element name="ahfs-codes" xdb:defaultTable="AHFS_CODES">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element name="ahfs-code" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug AHFS codes definition ends -->
         <!-- Drug Patent definition begins -->
         <xs:element name="patent">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="number" type="xs:string"/>
                        <xs:element name="country" type="xs:string"/>
                        <xs:element name="approved" type="xs:string"/>
                        <xs:element name="expires" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:element name="patents" xdb:defaultTable="PATENTS">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element ref="patent"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug patent definition ends -->
         <!-- Drug food interactions definition begins -->
         <xs:element name="food-interactions" xdb:defaultTable="FOOD_INTERACTIONS">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="food-interaction" type="xs:string" maxOccurs="unbounded" minOccurs="0"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug food interactions definition ends -->
         <!-- Drug drug interactions definition begins -->
         <xs:element name="drug-interaction">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="drug" type="xs:integer"/>
                        <xs:element name="description" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:element name="drug-interactions" xdb:defaultTable="DRUG_INTERACTIONS">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element ref="drug-interaction"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug drug interactions definition ends -->
         <!-- Drug protein sequences (biotech) definition begins -->
         <xs:element name="protein-sequences" xdb:defaultTable="PROTEIN_SEQUENCES">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element name="protein-sequence" type="SequenceType"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug protein sequences (biotech) definition ends-->
         <!-- Drug external links definition begins -->
         <xs:element name="external-link">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="resource" type="xs:string"/>
                        <xs:element name="url" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:element name="external-links" xdb:defaultTable="EXTERNAL_LINKS">
              <xs:complexType>
                   <xs:sequence maxOccurs="unbounded" minOccurs="0">
                        <xs:element ref="external-link"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug external links definition ends -->
         <!-- Drug targets definition begins -->
         <xs:element name="targets" xdb:defaultTable="TARGETS">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="target" type="TargetBondType" minOccurs="0" maxOccurs="unbounded"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug targets definition ends -->
         <!-- Drug enzymes definition begins -->
         <xs:element name="enzymes" xdb:defaultTable="ENZYMES">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="enzyme" type="BondType" minOccurs="0" maxOccurs="unbounded"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug enzmes definition ends -->
         <!-- Drug transporters definition begins -->
         <xs:element name="transporters" xdb:defaultTable="TRANSPORTERS">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="transporter" type="BondType" minOccurs="0" maxOccurs="unbounded"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug transporters definition ends -->
         <!-- Drug carriers definition begins -->
         <xs:element name="carriers" xdb:defaultTable="CARRIERS">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="carrier" type="BondType" minOccurs="0" maxOccurs="unbounded"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Drug carriers definition ends -->
         <!-- Partner  Pfams definition begins -->
         <xs:element name="pfam">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="identifier" type="xs:string"/>
                        <xs:element name="name" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:element name="pfams" xdb:defaultTable="PFAMS">
              <xs:complexType>
                   <xs:sequence minOccurs="0" maxOccurs="unbounded">
                        <xs:element ref="pfam"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Partner  Pfams definition end -->
         <!-- Partner  GO Classification definition begins -->
         <xs:element name="go-classifier">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="category" type="xs:string"/>
                        <xs:element name="description" type="xs:string"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <xs:element name="go-classifiers" xdb:defaultTable="GO_CLASSIFIERS">
              <xs:complexType>
                   <xs:sequence minOccurs="0" maxOccurs="unbounded">
                        <xs:element ref="go-classifier"/>
                   </xs:sequence>
              </xs:complexType>
         </xs:element>
         <!-- Partner  GO Classification definition ends -->
         <!-- Partner Essentiality definition begins -->
         <xs:element name="essentiality">
              <xs:simpleType>
                   <xs:restriction base="xs:string">
                        <xs:enumeration value="Essential"/>
                        <xs:enumeration value="Non-Essential"/>
                   </xs:restriction>
              </xs:simpleType>
         </xs:element>
         <!-- Partner Essentiality definition ends -->
         <!-- Complex Type Definitions -->
         <xs:complexType name="SequenceType">
              <xs:sequence>
                   <xs:element name="header" type="xs:string"/>
                   <xs:element name="chain" type="xs:string"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="PropertyType">
              <xs:sequence>
                   <xs:element name="kind">
                        <xs:simpleType>
                             <xs:restriction base="xs:string">
                                  <xs:enumeration value="logP"/>
                                  <xs:enumeration value="logS"/>
                                  <xs:enumeration value="logP/hydrophobicity"/>
                                  <xs:enumeration value="Water Solubility"/>
                                  <xs:enumeration value="caco2 Permeability"/>
                                  <xs:enumeration value="pKa"/>
                                  <xs:enumeration value="IUPAC Name"/>
                                  <xs:enumeration value="Molecular Weight"/>
                                  <xs:enumeration value="Monoisotopic Weight"/>
                                  <xs:enumeration value="SMILES"/>
                                  <xs:enumeration value="Molecular Formula"/>
                                  <xs:enumeration value="InChI"/>
                                  <xs:enumeration value="InChIKey"/>
                             </xs:restriction>
                        </xs:simpleType>
                   </xs:element>
                   <xs:element name="value" type="xs:string"/>
                   <xs:element name="source">
                        <xs:simpleType>
                             <xs:restriction base="xs:string">
                                  <xs:enumeration value="JChem"/>
                                  <xs:enumeration value="ALOGPS"/>
                                  <xs:enumeration value=""/>
                             </xs:restriction>
                        </xs:simpleType>
                   </xs:element>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="PropertiesType">
              <xs:sequence>
                   <xs:element name="property" type="PropertyType" minOccurs="0" maxOccurs="unbounded"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="SynonymsType">
              <xs:sequence maxOccurs="unbounded" minOccurs="0">
                   <xs:element name="synonym" type="xs:string"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="IdentifiersType">
              <xs:sequence maxOccurs="unbounded" minOccurs="0">
                   <xs:element name="external-identifier">
                        <xs:complexType>
                             <xs:sequence>
                                  <xs:element name="resource" type="xs:string"/>
                                  <xs:element name="identifier" type="xs:string"/>
                             </xs:sequence>
                        </xs:complexType>
                   </xs:element>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="BondActionsType">
              <xs:sequence maxOccurs="unbounded" minOccurs="0">
                   <xs:element name="action" type="xs:string"/>
              </xs:sequence>
         </xs:complexType>
         <xs:complexType name="BondType">
              <xs:sequence>
                   <xs:element name="actions" type="BondActionsType"/>
                   <xs:element name="references" type="xs:string"/>
              </xs:sequence>
              <xs:attribute name="position" type="xs:integer" use="optional"/>
              <xs:attribute name="partner" type="xs:integer"/>
         </xs:complexType>
         <xs:complexType name="TargetBondType">
              <xs:complexContent>
                   <xs:extension base="BondType">
                        <xs:sequence>
                             <xs:element name="known-action">
                                  <xs:simpleType>
                                       <xs:restriction base="xs:string">
                                            <xs:enumeration value="yes"/>
                                            <xs:enumeration value="no"/>
                                            <xs:enumeration value="unknown"/>
                                       </xs:restriction>
                                  </xs:simpleType>
                             </xs:element>
                        </xs:sequence>
                   </xs:extension>
              </xs:complexContent>
         </xs:complexType>
         <xs:complexType name="PartnerType">
              <xs:sequence>
                   <xs:element name="name" type="xs:string"/>
                   <xs:element name="general-function" type="xs:string"/>
                   <xs:element name="specific-function" type="xs:string"/>
                   <xs:element name="gene-name" type="xs:string"/>
                   <xs:element name="locus" type="xs:string"/>
                   <xs:element name="reaction" type="xs:string"/>
                   <xs:element name="signals" type="xs:string"/>
                   <xs:element name="cellular-location" type="xs:string"/>
                   <xs:element name="transmembrane-regions" type="xs:string"/>
                   <xs:element name="theoretical-pi" type="DecimalOrEmptyType"/>
                   <xs:element name="molecular-weight" type="DecimalOrEmptyType"/>
                   <xs:element name="chromosome" type="xs:string"/>
                   <xs:element ref="essentiality"/>
                   <xs:element name="references" type="xs:string"/>
                   <xs:element name="external-identifiers" type="IdentifiersType"/>
                   <xs:element name="synonyms" type="SynonymsType"/>
                   <xs:element name="protein-sequence" type="SequenceType" minOccurs="0"/>
                   <xs:element name="gene-sequence" type="SequenceType" minOccurs="0"/>
                   <xs:element ref="pfams"/>
                   <xs:element ref="go-classifiers"/>
              </xs:sequence>
              <xs:attribute name="id" type="xs:integer" use="required"/>
         </xs:complexType>
         <xs:complexType name="DrugType">
              <xs:sequence>
                   <xs:element name="drugbank-id" type="xs:string"/>
                   <xs:element name="name" type="xs:string"/>
                   <xs:element name="description" type="xs:string"/>
                   <xs:element name="cas-number" type="xs:string"/>
                   <xs:element name="general-references" type="xs:string"/>
                   <xs:element name="synthesis-reference" type="xs:string"/>
                   <xs:element name="indication" type="xs:string"/>
                   <xs:element name="pharmacology" type="xs:string"/>
                   <xs:element name="mechanism-of-action" type="xs:string"/>
                   <xs:element name="toxicity" type="xs:string"/>
                   <xs:element name="biotransformation" type="xs:string"/>
                   <xs:element name="absorption" type="xs:string"/>
                   <xs:element name="half-life" type="xs:string"/>
                   <xs:element name="protein-binding" type="xs:string"/>
                   <xs:element name="route-of-elimination" type="xs:string"/>
                   <xs:element name="volume-of-distribution" type="xs:string"/>
                   <xs:element name="clearance" type="xs:string"/>
                   <xs:element ref="secondary-accession-numbers"/>
                   <xs:element ref="groups"/>
                   <xs:element ref="taxonomy"/>
                   <xs:element name="synonyms" type="SynonymsType"/>
                   <xs:element ref="brands"/>
                   <xs:element ref="mixtures"/>
                   <xs:element ref="packagers"/>
                   <xs:element ref="manufacturers"/>
                   <xs:element ref="prices"/>
                   <xs:element ref="categories"/>
                   <xs:element ref="affected-organisms"/>
                   <xs:element ref="dosages"/>
                   <xs:element ref="atc-codes"/>
                   <xs:element ref="ahfs-codes"/>
                   <xs:element ref="patents"/>
                   <xs:element ref="food-interactions"/>
                   <xs:element ref="drug-interactions"/>
                   <xs:element ref="protein-sequences" minOccurs="0"/><!-- Only present for biotech drugs -->
                   <xs:element name="calculated-properties" type="PropertiesType" minOccurs="0"/><!-- Only present for small molecule drugs -->
                   <xs:element name="experimental-properties" type="PropertiesType"/>
                   <xs:element name="external-identifiers" type="IdentifiersType"/>
                   <xs:element ref="external-links"/>
                   <xs:element ref="targets"/>
                   <xs:element ref="enzymes"/>
                   <xs:element ref="transporters"/>
                   <xs:element ref="carriers"/>
              </xs:sequence>
              <xs:attribute name="type" use="required">
                   <xs:simpleType>
                        <xs:restriction base="xs:string">
                             <xs:enumeration value="small molecule"/>
                             <xs:enumeration value="biotech"/>
                        </xs:restriction>
                   </xs:simpleType>
              </xs:attribute>
              <xs:attribute name="updated" type="xs:string" use="required"/>
              <xs:attribute name="created" type="xs:string" use="required"/>
              <xs:attribute name="version" type="xs:decimal" use="required"/>
         </xs:complexType>
         <xs:element name="drugs"  xdb:defaultTable="DRUGS">
              <xs:complexType>
                   <xs:sequence>
                        <xs:element name="drug" type="DrugType" minOccurs="0" maxOccurs="unbounded" />
                        <xs:element name="partners">
                             <xs:complexType>
                                  <xs:sequence>
                                       <xs:element name="partner" type="PartnerType" minOccurs="0" maxOccurs="unbounded" />
                                  </xs:sequence>
                             </xs:complexType>
                        </xs:element>
                   </xs:sequence>
              </xs:complexType>
              <xs:keyref name="targetPartnerIdKeyRef" refer="partnerIdKey">
                   <xs:selector xpath="drug/targets/*"/>
                   <xs:field xpath="@partner"/>
              </xs:keyref>
              <xs:keyref name="enzymePartnerIdKeyRef" refer="partnerIdKey">
                   <xs:selector xpath="drug/enzymes/*"/>
                   <xs:field xpath="@partner"/>
              </xs:keyref>
              <xs:keyref name="transporterPartnerIdKeyRef" refer="partnerIdKey">
                   <xs:selector xpath="drug/transporters/*"/>
                   <xs:field xpath="@partner"/>
              </xs:keyref>
              <xs:keyref name="carrierPartnerIdKeyRef" refer="partnerIdKey">
                   <xs:selector xpath="drug/carriers/*"/>
                   <xs:field xpath="@partner"/>
              </xs:keyref>
              <xs:key name="partnerIdKey">
                   <xs:selector xpath=".//partner"/>
                   <xs:field xpath="@id"/>
              </xs:key>
         </xs:element>     
    </xs:schema>Query optimizing whitepaper
    http://www.oracle.com/technetwork/database/features/xmldb/xmlqueryoptimize11gr2-168036.pdf

    I attempted to insert the xml file into an xml table and into a relational table with an xml column both based on the schema. I get the same errors.
    -This creates an XML table based on the schema successfully
    CREATE TABLE pharma.drugs_xmltype OF XMLTYPE
    XMLSCHEMA "http://localhost:8080/home/pharma/drugbank.xsd"
    ELEMENT "drugs";
    Table created.
    Elapsed: 00:00:02.67
    SQL>desc pharma.drugs_xmltype
    Name                                                                          Null?    Type
    TABLE of SYS.XMLTYPE(XMLSchema "http://localhost:8080/home/pharma/drugbank.xsd" Element "drugs") STORAGE Object-relational TYPE "drugs1200_T"-- it refers to these types
    create or replace TYPE          "drugs1200_T" AS OBJECT ("SYS_XDBPD$" "XDB"."XDB$RAW_LIST_T","drug" "drug1201_COLL","partners" "partners1202_T")FINAL INSTANTIABLE
    create or replace TYPE          "drug1201_COLL" AS VARRAY(2147483647) OF "DrugType1121_T"
    create or replace TYPE          "partners1202_T" AS OBJECT ("SYS_XDBPD$" "XDB"."XDB$RAW_LIST_T","partner" "partner1203_COLL")FINAL INSTANTIABLE
    create or replace TYPE          "partner1203_COLL" AS VARRAY(2147483647) OF "PartnerType1190_T"
    create or replace TYPE          "DrugType1121_T" AS OBJECT ("SYS_XDBPD$" "XDB"."XDB$RAW_LIST_T","type" "XDB"."XDB$ENUM_T","updated" VARCHAR2(4000 CHAR),"created" VARCHAR2(4000 CHAR),"version" NUMBER,"drugbank-id" VARCHAR2(4000 CHAR),"name" VARCHAR2(4000 CHAR),"description" VARCHAR2(4000 CHAR),"cas-number" VARCHAR2(4000 CHAR),"general-references" VARCHAR2(4000 CHAR),"synthesis-reference" VARCHAR2(4000 CHAR),"indication" VARCHAR2(4000 CHAR),"pharmacology" VARCHAR2(4000 CHAR),"mechanism-of-action" VARCHAR2(4000 CHAR),"toxicity" VARCHAR2(4000 CHAR),"biotransformation" VARCHAR2(4000 CHAR),"absorption" VARCHAR2(4000 CHAR),"half-life" VARCHAR2(4000 CHAR),"protein-binding" VARCHAR2(4000 CHAR),"route-of-elimination" VARCHAR2(4000 CHAR),"volume-of-distribution" VARCHAR2(4000 CHAR),"clearance" VARCHAR2(4000 CHAR),"secondary-accession-numbers" "secondary-accession1122_T","groups" "groups1124_T","taxonomy" "taxonomy1126_T","synonyms" "SynonymsType1131_T","brands" "brands1132_T","mixtures" "mixtures1133_T","packagers" "packagers1137_T","manufacturers" "manufacturers1141_T","prices" "prices1145_T","categories" "categories1151_T","affected-organisms" "affected-organisms1152_T","dosages" "dosages1153_T","atc-codes" "atc-codes1157_T","ahfs-codes" "ahfs-codes1158_T","patents" "patents1159_T","food-interactions" "food-interactions1163_T","drug-interactions" "drug-interactions1164_T","protein-sequences" "protein-sequences1168_T","calculated-properties" "PropertiesType1171_T","experimental-properties" "PropertiesType1171_T","external-identifiers" "IdentifiersType1174_T","external-links" "external-links1177_T","targets" "targets1181_T","enzymes" "enzymes1186_T","transporters" "transporters1188_T","carriers" "carriers1189_T")NOT FINAL INSTANTIABLE -- drugs type
    PHARMA@scidev> desc "drugs1200_T"
    Name          Null?    Type
    SYS_XDBPD$             XDB.XDB$RAW_LIST_T
    drug                   drug1201_COLL
    partners               partners1202_T-- I planned to insert using a subselect and got the same error on the select.
    Error starting at line 1 in command:
    SELECT max(length(drugbank_id)) AS dbidlen
    FROM (XMLTABLE('*'
                    PASSING (XMLType(bfilename('XMLPHARMA', 'drugbank.xml'),nls_charset_id('AL32UTF8')))
                    COLUMNS
        drugbank_id        VARCHAR2(20)   PATH 'drug/drugbank-id'
    Error report:
    SQL Error: ORA-31011: XML parsing failed
    ORA-19202: Error occurred in XML processing
    LPX-00007: unexpected end-of-file encountered
    31011. 00000 -  "XML parsing failed"
    *Cause:    XML parser returned an error while trying to parse the document.
    *Action:   Check if the document to be parsed is valid.--This creates a row in the xmltype table from a single drug file.
    INSERT INTO drugs_xmltype
    VALUES(XMLType(bfilename('XMLPHARMA', 'db00001.xml'),nls_charset_id('AL32UTF8')).CreateSchemaBasedXML(
        'http://localhost:8080/home/pharma/drugbank.xsd'))
    ;-- The create using the full xml file fails.
    INSERT INTO drugs_xmltype
    VALUES(XMLType(bfilename('XMLPHARMA', 'drugbank.xml'),nls_charset_id('AL32UTF8')).CreateSchemaBasedXML(
    'http://localhost:8080/home/pharma/drugbank.xsd'))
    VALUES(XMLType(bfilename('XMLPHARMA', 'drugbank.xml'),nls_charset_id('AL32UTF8')).CreateSchemaBasedXML(
    ERROR at line 2:
    ORA-30951: Element or attribute at Xpath references exceeds maximum length
    Elapsed: 00:01:17.90-- Then I tried the same using a relational table with an xml column
    -- Then I created a relational table with an xml column
    CREATE TABLE pharma.drugs_xmlcolumn_type (drug_xml XMLTYPE)
    XMLTYPE COLUMN drug_xml STORE AS OBJECT RELATIONAL
    XMLSCHEMA "http://localhost:8080/home/pharma/drugbank.xsd"
    ELEMENT "drugs";
    CREATE TABLE succeeded.--This command refers to the following types
    SYS.XMLTYPE(XMLSchema "http://localhost:8080/home/pharma/drugbank.xsd" Element "drugs" ) STORAGE Object-relational TYPE "drugs1200_T"-- This creates a row in the xmlcolumn table from a single drug file.
    INSERT INTO drugs_xmlcolumn_type
    VALUES(XMLType(bfilename('XMLPHARMA', 'db00001.xml'),nls_charset_id('AL32UTF8')).CreateSchemaBasedXML(
        'http://localhost:8080/home/pharma/drugbank.xsd'))
    ;--The create using the full xml file into a relational table with an xml column fails
    INSERT INTO drugs_xmlcolumn_type
    VALUES(XMLType(bfilename('XMLPHARMA', 'drugbank.xml'),nls_charset_id('AL32UTF8')).CreateSchemaBasedXML(
    'http://localhost:8080/home/pharma/drugbank.xsd'))
    VALUES(XMLType(bfilename('XMLPHARMA', 'drugbank.xml'),nls_charset_id('AL32UTF8')).CreateSchemaBasedXML(
    ERROR at line 2:
    ORA-30951: Element or attribute at Xpath references exceeds maximum length
    Elapsed: 00:01:06.74

  • XPath little problem

    Hello
    This is my first problem which can not be solved by myself
    Here is an excerpt of my XML file:
    <films>
          <history>
             <data>
                <title>Predator</title>
                <year>1987</year>
             </data>
             <data>
                <title>Rocky 3</title>
                <year>1982</year>
             </data>
             <data>
                <title>Hercules</title>
                <year>1970</year>
             </data>
             <data>
                <title>Conan the Barbarian</title>
                <year>1982</year>
             </data>
             <data>
                <title>Conan the Destroyer</title>
                <year>1984</year>
             </data>
          </history>
    </films>And my question is.
    Can i build a querry with(with member functions like extractvalue, extract etc.) which gives me result like:
    only those films which were created in the 1882 year
    something like that :
    Conan the Barbarian
    Rocky 3
    Im waiting for your reply
    regards :)
    Edited by: Jaco35 on 2010-05-02 07:50
    Edited by: Jaco35 on 2010-05-02 14:20

    Hi,
    Differents ways, depending on your db version.
    Prior to 10g :
    WITH t AS (
    SELECT xmltype(
    '<films>
    <history>
    <data><title>Predator</title><year>1987</year></data>
    <data><title>Rocky 3</title><year>1982</year></data>
    <data><title>Hercules</title><year>1970</year></data>
    <data><title>Conan the Barbarian</title><year>1982</year></data>
    <data><title>Conan the Destroyer</title><year>1984</year></data>
    </history>
    </films>'
    ) doc
    FROM dual
    SELECT extractvalue(x.column_value, '.') as title
    FROM t, TABLE(
      XMLSequence(
        extract(t.doc, 'films/history/data[year="1982"]/title')
    ) x;Starting with 10g, prefer the use of XMLTable :
    WITH t AS (
    SELECT xmltype(
    '<films>
    <history>
    <data><title>Predator</title><year>1987</year></data>
    <data><title>Rocky 3</title><year>1982</year></data>
    <data><title>Hercules</title><year>1970</year></data>
    <data><title>Conan the Barbarian</title><year>1982</year></data>
    <data><title>Conan the Destroyer</title><year>1984</year></data>
    </history>
    </films>'
    ) doc
    FROM dual
    SELECT x.*
    FROM t, XMLTable(
      'films/history/data[year="1982"]/title'
      passing t.doc
      columns
        title varchar2(30) path '.'
    ) x;Or :
    WITH t AS (
    SELECT xmltype(
    '<films>
    <history>
    <data><title>Predator</title><year>1987</year></data>
    <data><title>Rocky 3</title><year>1982</year></data>
    <data><title>Hercules</title><year>1970</year></data>
    <data><title>Conan the Barbarian</title><year>1982</year></data>
    <data><title>Conan the Destroyer</title><year>1984</year></data>
    </history>
    </films>'
    ) doc
    FROM dual
    SELECT x.title
    FROM t, XMLTable(
      'films/history/data'
      passing t.doc
      columns
        title varchar2(30) path 'title',
        year  number(4)    path 'year'
    ) x
    WHERE year = 1982;HTH.

  • XML Partitioning in Oracle 10.2

    Was wondering regarding a possible opportunity with a broker client, is it possible (or will there be a back patch or sorts) to XML partition as known in 11.1.0.7 for XMLType OR, lets say Oracle database version 10.2.0.5.0 ?
    Thx
    Marco

    Have you read the deprecated features list in 11.2? Not that it is that important, they will be supported for a while to come, and internally (eg. packages) they make still use of things like extractvalue, extract, etc, but regarding the functional index approach, there are definitely better solutions in Oracle 11gRx like the (unstructured) XMLIndex...

  • Fetch XML file data

    Hi All,
    Please can you give an idea how to fech xml data..I wanto fetch all <POL_NO> tag data in a temp table.
    My sample xml:
    <POL>
    <Polinfo>
    <POL_NAME>COMP1</POL_NAME>
    <POL_NO>100</POL_NO>
    </Polinfo>
    </POL>
    <POL>
    <Polinfo>
    <POL_NAME>COMP2</POL_NAME>
    <POL_NO>101</POL_NO>
    </Polinfo>
    </POL>
    <POL>
    <Polinfo>
    <POL_NAME>COMP3</POL_NAME>
    <POL_NO>102</POL_NO>
    </Polinfo>
    </POL>
    <POL>
    <Polinfo>
    <POL_NAME>COMP4</POL_NAME>
    <POL_NO>103</POL_NO>
    </Polinfo>
    </POL>
    Thanks,

    The EXTRACTVALUE and XMLSEQUENCE method is deprecated in 11g, and from 10g you would be better using the XMLTABLE method:
    SQL> ed
    Wrote file afiedt.buf
      1  with t as (select xmltype('<root>
      2  <POL>
      3    <Polinfo>
      4      <POL_NAME>COMP1</POL_NAME>
      5      <POL_NO>100</POL_NO>
      6    </Polinfo>
      7  </POL>
      8  <POL>
      9    <Polinfo>
    10      <POL_NAME>COMP2</POL_NAME>
    11      <POL_NO>101</POL_NO>
    12    </Polinfo>
    13  </POL>
    14  <POL>
    15    <Polinfo>
    16      <POL_NAME>COMP3</POL_NAME>
    17      <POL_NO>102</POL_NO>
    18    </Polinfo>
    19  </POL>
    20  <POL>
    21    <Polinfo>
    22      <POL_NAME>COMP4</POL_NAME>
    23      <POL_NO>103</POL_NO>
    24    </Polinfo>
    25  </POL>
    26  </root>') as xml from dual)
    27  --
    28  -- end of test data
    29  --
    30  select x.*
    31  from   t
    32        ,xmltable('/root/POL'
    33                  passing t.xml
    34                  columns pol_name varchar2(10) path './Polinfo/POL_NAME'
    35                         ,pol_no   number       path './Polinfo/POL_NO'
    36*                ) x
    SQL> /
    POL_NAME       POL_NO
    COMP1             100
    COMP2             101
    COMP3             102
    COMP4             103

  • Update with subquery

    I want to update a table with data extracted from a xmltype.
    But Oracle extracts only the first value from the subquery.
    Am I missing something or this is the expected output...
    drop table t
    create table t(id number, val varchar2(20));
    insert into t(id, val) values (1, null)
    insert into t(id, val) values (2, null)
    select *
    from t
    ID     VAL
    1     
    2     
    update t set(val) =
    (select t.id from dual)
    where id = t.id
    select *
    from t
    ID     VAL
    1     1
    2     2
    update t set(val) =
    (select extractValue(
                   extract(xmltype('<root>'||
                                       '<node id="1">'||
                                       '<value>1</value>'||
                                       '</node>'||
                                       '<node id="2">'||
                                       '<value>2</value>'||
                                       '</node>'||
                                       '</root>'),
                             '//root/node[@id='||to_char(t.id)||']'),
                   '/node/value') from dual)
    where id = t.id
    select *
    from t
    ID     VAL
    1     1
    2     1 -- <-- should be 2!

    Hi,
    try this way:
    SQL> CREATE TABLE tab AS SELECT 1 id,cast(NULL AS VARCHAR2(20)) val FROM dual UNION ALL
      2                      SELECT 2,NULL FROM dual;
    Table created.
    SQL> DESC tab;
    Name                                      Null?    Type
    ID                                                 NUMBER
    VAL                                                VARCHAR2(20)
    SQL>
    SQL> SELECT * FROM tab;
            ID VAL                                                                 
             1                                                                     
             2                                                                     
    SQL>
    SQL> UPDATE tab t
      2  SET val=(
      3      SELECT
      4         extractValue(
      5            extract(
      6               XMLType('<root>
      7                          <node id="1">
      8                            <value>1</value>
      9                          </node>
    10                          <node id="2">
    11                            <value>2</value>
    12                          </node>
    13                        </root>')
    14               ,'/root/node[@id='||id||']')
    15            ,'/node/value') va
    16      FROM tab s
    17    WHERE t.id=s.id) ;
    2 rows updated.
    SQL> SELECT * FROM tab;
            ID VAL                                                                 
             1 1                                                                   
             2 2                                                                   
    SQL> spool off;btw, you don't need to || every line in xml, and you don't need to do to_char() when using ||
    Ants

  • Process xml

    Hi,
    I have large xml file and I want to process it by databse.
    How can I get the information from this file,.
    I searched in the forums but I did not get the main idea
    I made direcotor as
    (CREATE OR REPLACE DIRECTORY XMLDIR as 'C:\XML')
    I putted the file in this directory.
    and after that I created table as
    (create table Table_XML of XMLType)
    and inserted in this table the following:
    ( insert into Table_XML values ( xmltype(bfilename('XMLDIR','XMLF.XML'),nls_charset_id('AL332UTF8')) ) )
    where XMLF>XML is my xml file
    But How can I manioulate this file , and how can I get the information from it any Idea about this.
    Thanks For all
    Mohd
    Edited by: For Best on May 14, 2009 6:39 AM

    Some pointers could be updateXML, extractvalue, extract, xmltable, xmlquery, etc. Is that what you wanted to know?
    Also maybe start here: http://download.oracle.com/docs/cd/B28359_01/appdev.111/b28369/xdb04cre.htm#g1050045

  • XMLSequence EXTRACT HEAD and DETAIL in ORACLE 9.2

    Hi, sorry about my english i am from argentine.
    I have this XML:
    <?xml version="1.0" encoding="UTF-8" standalone="yes"?>
    <arrayOfServicio >
        <Servicio>
            <Nombre>Autenticacion</Nombre>
            <Descripcion>ws</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>RequestTicket</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>Consultas</Nombre>
            <Descripcion>wsConsultas</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>GetVigencia</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
                <Metodo>
                    <Nombre>GetSiniestralidad</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
                <Metodo>
                    <Nombre>GetAgrupados</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
                <Metodo>
                    <Nombre>GetSiniestralidadPorCuil</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>Referencias</Nombre>
            <Descripcion>wsReferencias</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>TablaReferencia</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
                <Metodo>
                    <Nombre>ListadoReferencia</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>General</Nombre>
            <Descripcion>WsGeneral</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>GetServicios</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>eServicios</Nombre>
            <Descripcion>wseServicios</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>SetComunicacion</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>VentanillaART</Nombre>
            <Descripcion>wsVentanillaART</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>ObtenerNovedades</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
        <Servicio>
            <Nombre>Establecimientos</Nombre>
            <Descripcion>wsEstablecimiento</Descripcion>
            <Activo>true</Activo>
            <Version>1.0</Version>
            <MetodosEntity>
                <Metodo>
                    <Nombre>GetConsultaPorCuit</Nombre>
                    <Activo>true</Activo>
                    <Version>1.0</Version>
                </Metodo>
            </MetodosEntity>
        </Servicio>
    </arrayOfServicio>
    I am working in ORACLE 9.2 and i wrote this query but the result is not correct, i need to join HEAD and DETAIL in some way but cannot do that...
      select extractvalue(value(head),'//Servicio/Nombre/text()') ,
            extractvalue(value(head),'//Servicio/Descripcion/text()'),
            extractvalue(value(head),'//Servicio/Activo/text()'),
            extractvalue(value(head),'//Servicio/Version/text()')
            ,extractvalue(value(detail),'//Metodo/Nombre/text()')
            ,extractvalue(value(detail),'//Metodo/Activo/text()')
            ,extractvalue(value(detail),'//Metodo/Version/text()')
      from arwt_ws_return x
          , table(xmlsequence(extract (x.x_xmldoc, '/arrayOfServicio/Servicio'))) head
          , table(xmlsequence(extract (x.x_xmldoc, '/arrayOfServicio/Servicio/MetodosEntity/Metodo'))) detail;
    Ii really appreciate your help.
    Thanks!

    Hi,
    You can do that by passing the head element to the second XMLSequence. That way you maintain the correlation between the parent and its children :
    select extractvalue(value(head), '/Servicio/Nombre') as srv_nombre
         , extractvalue(value(head), '/Servicio/Descripcion') as srv_desc
         , extractvalue(value(head), '/Servicio/Activo') as srv_activo
         , extractvalue(value(head), '/Servicio/Version') as srv_version
         , extractvalue(value(detail), '/Metodo/Nombre') as met_nombre
         , extractvalue(value(detail), '/Metodo/Activo') as met_activo
         , extractvalue(value(detail), '/Metodo/Version') as met_version
    from arwt_ws_return x
       , table(xmlsequence(extract(x.x_xmldoc, '/arrayOfServicio/Servicio'))) head
       , table(xmlsequence(extract(value(head), '/Servicio/MetodosEntity/Metodo'))) detail
    Please also note that :
    - you don't need a descendant axis (//) if you know the exact path
    - you don't need to go down to the text() node if you're using extractvalue
    Hope that helps.

  • Using extractvalue with XMLTYPE to extract multiple nodes

    hi ,
    I'm trying to fetch data from xml which is stored as clob in db (10g) ,
    when i tried to fetch with query as below
    SELECT extractvalue(XMLTYPE(xjm.X_MSG_XML), '//orderRequest/order/orderItem/alternativeIdentifer/value') uiid
    FROM TABLE_X_MSG_ATTR xma, TABLE_X_JMS_MSG xjm
    WHERE xma.X_MSG_ATTR2X_JMS_MSG=xjm.OBJID
    AND xma.X_ATTR_NAME='MOP_ID'
    AND xma.X_ATTR_VALUE in ('RJM78999')
    and got **ORA-19025: EXTRACTVALUE returns value of only one node**
    so i modified it as below
    SELECT extractvalue(value(x), '//orderRequest/order/orderItem/alternativeIdentifer/value') uiid
    FROM TABLE_X_MSG_ATTR xma, TABLE_X_JMS_MSG xjm
    ,TABLE(XMLSequence(extractvalue(XMLTYPE(xjm.X_MSG_XML),'//orderRequest/order/orderItem/alternativeIdentifer/value'))) x
    WHERE xma.X_MSG_ATTR2X_JMS_MSG=xjm.OBJID
    AND xma.X_ATTR_NAME='MOP_ID'
    AND xma.X_ATTR_VALUE in ('RJM78999')
    ORA-29900: operator binding does not exist
    ORA-06553: PLS-306: wrong number or types of arguments in call to 'XMLSEQUENCE'
    no success :( it is working for single record (node)all perfect
    Thnkz
    Edited by: Volution2111 on Sep 11, 2010 5:08 AM
    Edited by: Volution2111 on Sep 11, 2010 5:10 AM

    Difficult to give the exact answer without knowing which node repeats..
    Howver it will be something like this
    select extractValue(value(x),'/RepeatingNode/NonRepatingNode/NonRepeatingNode)
      from TABLE, table(xmlsequence(extract(xmltype(clob),'/Root/Node/RepeatingNode')))) x

  • SQL functions extract and XMLSequence for a one-to-many (1:N) relationship

    I have have the following XML document loaded into a XMLType table. I'd like to retrieve the lineitem id together with the purchaseorder id and report id. How would the query look like? I've tried a lot but this one-to-many relationship is killing me.
    Many thanks!
    <report id=...>
    <purchaseorder id=...>
    <lineitems>
    <lineitem id=...>...</lineitem>
    <lineitem id=...>...</lineitem>
    <lineitem id=...>...</lineitem>
    </lineitems>
    </purchaseorder>
    <purchaseorder id=...>
    <lineitems>
    <lineitem id=...>...</lineitem>
    </lineitems>
    </purchaseorder>

    You can easily modify the above query to your needs:
    SQL> with qry as (
      2  select t.column_value.extract('/report/@id') report_id,
      3         t.column_value.extract('/report/purchaseorder') purchaseorder,
      4         t.column_value.extract('/report/purchaseorder/lineitems/*') lineitems
      5  from table(xmlsequence(xmltype('<document>
      6                                    <chapter>
      7                                      <report id="1">
      8                                        <purchaseorder id="1">
      9                                          <lineitems>
    10                                            <lineitem id="1">Item 11</lineitem>
    11                                            <lineitem id="2">Item 12</lineitem>
    12                                            <lineitem id="3">Item 13</lineitem>
    13                                          </lineitems>
    14                                        </purchaseorder>
    15                                        <purchaseorder id="2">
    16                                          <lineitems>
    17                                            <lineitem id="1">Item 21</lineitem>
    18                                          </lineitems>
    19                                        </purchaseorder>
    20                                      </report>
    21                                      <report id="2">
    22                                        <purchaseorder id="1">
    23                                          <lineitems>
    24                                            <lineitem id="1">Item 31</lineitem>
    25                                            <lineitem id="2">Item 32</lineitem>
    26                                          </lineitems>
    27                                        </purchaseorder>
    28                                        <purchaseorder id="2">
    29                                          <lineitems>
    30                                            <lineitem id="1">Item 41</lineitem>
    31                                            <lineitem id="2">Item 42</lineitem>
    32                                          </lineitems>
    33                                        </purchaseorder>
    34                                      </report>
    35                                    </chapter>
    36                                  </document>'
    37  ).extract('/document/chapter/*'))) t)
    38  select q.report_id,
    39         q1.column_value.extract('/purchaseorder/@id') purchase_id,
    40         q2.column_value.extract('/lineitem/@id') lineitem_id,
    41         q2.column_value.extract('/lineitem/text()') lineitem
    42  from qry q,
    43       table(xmlsequence(q.purchaseorder)) q1,
    44       table(xmlsequence(q1.extract('/purchaseorder/lineitems/*'))) q2
    45  /
    REPORT_ID  PURCHASE_ID     LINEITEM_ID     LINEITEM
    1          1               1               Item 11
    1          1               2               Item 12
    1          1               3               Item 13
    1          2               1               Item 21
    2          1               1               Item 31
    2          1               2               Item 32
    2          2               1               Item 41
    2          2               2               Item 42
    8 rows selected.
    SQL>

  • Xmltype extract/extractValue query problem

    I am tring to use xmltype extract/extractValue.
    The query result never shown up, instead, it only
    display 'Answer goes here' or "10 rows selected".
    Same select statement used in java program got a null
    return.
    Anybody knows why?
    Honglin
    SQL> select extractValue(xml_data, '/FAQ-LIST/QUESTION/RESPONSE/text()')
    2 from XMLTable
    3 where existsNode(xml_data, '/FAQ-LIST/QUESTION[QUERY="Question 1"]') = 1;
    EXTRACTVALUE(XML_DATA,'/FAQ-LIST/QUESTION/RESPONSE/TEXT()')
    Answer goes here.

    Can you provide the sample XML file?

  • XMLSequence and extract attribute

    Hi all,
    From this XML :
    <execute-transaction app-ref="SRSRSimpleMult" app-sn="458" login="CARNI">
         <context key="Env:LOGIN" value="CARNI"/>
         <context key="Env:APP_SN" value="458"/>
         <context key="Env:APP_REF" value="SRSRSimpleMult"/>
    </execute-transaction>I would like to extract all the "key" attribute...
    The following select returns the good result but all is in 1 row :
    select extract(XMLTYPE('<execute-transaction app-ref="SRSRSimpleMult" app-sn="458" login="CARNI">
         <context key="Env:LOGIN" value="CARNI"/>
         <context key="Env:APP_SN" value="458"/>
         <context key="Env:APP_REF" value="SRSRSimpleMult"/>
    </execute-transaction>'),'*/context/@key') FROM DUAL;So I use XMLSequence (and not XMLTable because I'm still on Oracle 10g1) but the following select returns nothing
    select COLUMN_VALUE FROM table(xmlsequence(extract(XMLTYPE('<execute-transaction app-ref="SRSRSimpleMult" app-sn="458" login="CARNI">
         <context key="Env:LOGIN" value="CARNI"/>
         <context key="Env:APP_SN" value="458"/>
         <context key="Env:APP_REF" value="SRSRSimpleMult"/>
    </execute-transaction>'),'*/context/@key')));However if I simply remove the "@key" in the XPath expression, the select gives me back a good result ! (but with the context tag that I don't care)
    Can someone tell me why the SELECT doesn't return a result when the xpath expression contains the "@key" attribute ?
    Thx

    select xt.*
    FROM  table(xmlsequence(extract(XMLTYPE
                        ('<execute-transaction app-ref="SRSRSimpleMult" app-sn="458" login="CARNI">
                            <context key="Env:LOGIN" value="CARNI"/>
                            <context key="Env:APP_SN" value="458"/>
                            <context key="Env:APP_REF" value="SRSRSimpleMult"/>
                          </execute-transaction>')
                                   , '/execute-transaction/context'))) xt;
    COLUMN_VALUE
    <context key="Env:LOGIN" value="CARNI"/>
    <context key="Env:APP_SN" value="458"/>
    <context key="Env:APP_REF" value="SRSRSimpleMult"/>
    3 rows selected
    select rownum as "ROW"
         , extract(value(xt),'/context/@key') as "RESULT"
    FROM   table(xmlsequence(extract(XMLTYPE
                         ('<execute-transaction app-ref="SRSRSimpleMult" app-sn="458" login="CARNI">
                             <context key="Env:LOGIN" value="CARNI"/>
                             <context key="Env:APP_SN" value="458"/>
                             <context key="Env:APP_REF" value="SRSRSimpleMult"/>
                            </execute-transaction>')
                                     , '/execute-transaction/context'))) xt;
    ROW RESULT
      1 Env:LOGIN
      2 Env:APP_SN
      3 Env:APP_REF
    3 rows selectedEdited by: Marco Gralike on Mar 30, 2011 12:43 PM

  • Extracting data from XML using  extractValue

    Given the following XML stored as xmlType in the database(table name
    :opfdata) , i woiuld like to query it using extractValue,existsNode to
    retrieve the title of the book (dc:Title).
    i wrote the following query
    select e.existsNode('/package/metadata/dc-metadata/dc-Title
    unique-identifier="uid"') from opfdata e;
    Gives result as 1.
    But if i run change existNode to extractValue it gives me an error
    daying the xpath expression is wrong.
    Any ideas?
    <package unique-identifier="uid"
    xmlns="http://openebook.org/namespaces/oeb-package/1.0/">
    <!-- Metadata follows, Dublin core plus any metadata extensions-->
    <metadata>
    <dc-metadata xmlns:dc="http://purl.org/dc/elements/1.0/"
    xmlns:oebpackage="http://openebook.org/namespaces/oeb-package/1.0/">
    <dc:Title>Midnight Come Again</dc:Title>
    <dc:Subject>Shugak, Kate (Fictitious character)
    Fiction.</dc:Subject>
    <dc:Subject>Women private investigators -- Alaska
    Fiction.</dc:Subject>
    <dc:Subject>Smuggling Fiction.</dc:Subject>
    <dc:Subject>Alaska Fiction.</dc:Subject>
    <dc:Subject>Mystery fiction.</dc:Subject>
    <dc:Identifier id="uid"
    scheme="DTB">us-nls-db00010</dc:Identifier>
    <dc:Creator role="aut">Dana Stabenow</dc:Creator>
    <dc:Source>ISBN-0-312-20596-1</dc:Source>
    <dc:Publisher>National Library Service for the Blind and
    Physically
    Handicapped</dc:Publisher>
    <dc:Date>2002-5</dc:Date>
    <dc:Format>ANSI/NISO Z39.86-2002</dc:Format>
    <dc:Description>Following the death of her lover, in Hunter's
    Moon (RC 49633), depressed Kate Shugak takes a job in a coastal
    village as a cargo pilot. Meanwhile Alaska state trooper Jim Chopin is
    sent there under cover to investigate Russian smugglers. Some explicit
    descriptions of sex, some violence, and some strong language. 2000.
    </dc:Description>
    <dc:Language>en</dc:Language>
    </dc-metadata>
    </package>

    Hi,
    First of all what is the result of the query
    select e.existsNode('/package/metadata/dc-metadata/dc-Title
    unique-identifier="uid"') from opfdata e;
    existsNode returns 1 if it finds the row and 0 if it doesn't find the node.
    The xpath which you need to give to retrieve to retrieve the title of the book is:
    '/package/metadata/dc-metadata/title'
    You can refer the following link to know more about existsNode and extractValue
    http://otn.oracle.com/docs/products/oracle9i/doc_library/release2/appdev.920/a96620/xdb03usg.htm#1036760
    You can check the samples on XML DB which uses the different functionalities of Oracle XML DB.
    http://otn.oracle.com/sample_code/tech/xml/xmldb/content.html
    Check the Survey Sample which uses many features of XML DB. The sample is located at:
    http://otn.oracle.com/sample_code/tech/xml/survey/content.html
    and the various features used in the sample are explained in the page:
    http://otn.oracle.com/sample_code/tech/xml/survey/docs/AboutOracleXMLDB.html
    Regards,
    Anupama
    http://otn.oracle.com/sample_code/content.html

  • Extract parent and child data from an XML sequence?

    I'm very new to XML, so please excuse me if I use incorrect terminology here. I've been given a schema definition (.xsd), and several sample xml files from which I need to extract data and insert it into relational tables. I've made some progress in that I've been able to hack enough to modify and register the schema and get the XML into the database both through the registered schema and into a separate table with an XMLType column. I've also been able to use the isSchemaValid function to validate the XML against the schema definition, and I've been able to extract some of the simple data elements via the extractValue function. My problem is with extracting some of the nested data - that is, extracting parent node elements and child node elements together where there is more than one value in the child node. BTW. I'm on Oracle 10gR2.
    Following are the .xsd and and sample XML. Specifically, I need to select the NPI value from the PROVIDER node, and associate it with each of the CODE values from the SPECIALTIES node (which is part of the PROVIDER node).
    Here's the .xsd (sorry, it's very long). The only modifications I've made to the schema definition are to add the xdb namespace and the "xdb:defaultTable="HMOSCHEMA" snippet:
    <?xml version="1.0" encoding="UTF-8"?>
    <xsd:schema xmlns:xsd="http://www.w3.org/2001/XMLSchema"
    xmlns:xdb="http://xmlns.oracle.com/xdb" version="1.0">
    <xsd:element name="HMO" xdb:defaultTable="HMOSCHEMA">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element ref="HMO_GENERAL_INFORMATION" />
    <xsd:element ref="PROVIDERS" />
    <xsd:element ref="FACILITIES" minOccurs="0"
    maxOccurs="1" />
    </xsd:sequence>
    <xsd:attribute name="DATE" type="xsd:string" />
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="HMO_GENERAL_INFORMATION">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element ref="MCO_ID_LIST" minOccurs="1" maxOccurs="1" />
    <xsd:element ref="HMO_WEBSITE_ADDRESS" minOccurs="1"
    maxOccurs="1" />
    <xsd:element ref="HMO_SPECIAL_SERVICES" minOccurs="0"
    maxOccurs="1" />
    <xsd:element ref="HMO_DAILY_CONTACT_EMAIL_ADDRESS"
    minOccurs="1" maxOccurs="1" />
    <xsd:element ref="HMO_MONTHLY_CONTACT_EMAIL_ADDRESS"
    minOccurs="1" maxOccurs="1" />
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="PROVIDERS">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element maxOccurs="unbounded" ref="PROVIDER" />
    </xsd:sequence>
    <xsd:attribute name="RECORDS" type="xsd:string" />
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="PROVIDER">
    <xsd:complexType>
    <xsd:sequence minOccurs="1" maxOccurs="unbounded">
    <xsd:element ref="NPI" minOccurs="1" maxOccurs="1" />
    <xsd:element ref="FIRST_NAME" minOccurs="1"
    maxOccurs="1" />
    <xsd:element ref="LAST_NAME" minOccurs="1"
    maxOccurs="1" />
    <xsd:element ref="MIDDLE_INITIAL" minOccurs="0"
    maxOccurs="1" />
    <xsd:element ref="GENDER" minOccurs="1" maxOccurs="1" />
    <xsd:element ref="LINE_1_ADDRESS" minOccurs="1"
    maxOccurs="1" />
    <xsd:element ref="LINE_2_ADDRESS" minOccurs="0"
    maxOccurs="1" />
    <xsd:element ref="CITY" minOccurs="1" maxOccurs="1" />
    <xsd:element ref="STATE" minOccurs="1" maxOccurs="1" />
    <xsd:element ref="ZIP" minOccurs="1" maxOccurs="1" />
    <xsd:element ref="COUNTY" minOccurs="0" maxOccurs="1" />
    <xsd:element ref="PHONE_NUMBER" minOccurs="1"
    maxOccurs="1" />
    <xsd:element ref="CLINIC_NAME" minOccurs="0"
    maxOccurs="1" />
    <xsd:element ref="CLINIC_TYPE" minOccurs="0"
    maxOccurs="1" />
    <xsd:element ref="CLINIC_NPI" minOccurs="0"
    maxOccurs="1" />
    <xsd:element ref="PROVIDER_OFFICE_HOURS_TENTHS"
    minOccurs="0" maxOccurs="1" />
    <xsd:element ref="MAXIMUM_PATIENTS" minOccurs="0"
    maxOccurs="1" />
    <xsd:element ref="ACCEPT_NEW_PATIENT" minOccurs="0"
    maxOccurs="1" />
    <xsd:element ref="PRIMARY_CARE_INDICATOR" minOccurs="0"
    maxOccurs="1" />
    <xsd:element ref="FOREIGN_LANGUAGES" minOccurs="0"
    maxOccurs="1" />
    <xsd:element ref="SPECIALTIES" minOccurs="1"
    maxOccurs="1" />
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="SPECIALTIES">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element maxOccurs="unbounded" name="CODE"
    minOccurs="1">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[0-9]{3}" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="FACILITIES">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element maxOccurs="unbounded" ref="FACILITY_NUM"
    minOccurs="0" />
    </xsd:sequence>
    <xsd:attribute name="RECORDS" type="xsd:string" />
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="FOREIGN_LANGUAGES">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element maxOccurs="unbounded" name="CODE"
    minOccurs="0">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[A-Z]{3}" />
    <xsd:pattern value="[a-z]{3}" />
    <xsd:pattern value="" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="HMO_SPECIAL_SERVICES">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element maxOccurs="unbounded" name="CODE"
    minOccurs="0">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[0-9]{2}" />
    <xsd:pattern value="" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="MCO_ID_LIST">
    <xsd:complexType>
    <xsd:sequence>
    <xsd:element name="MCO_ID" minOccurs="1" maxOccurs="unbounded">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[0-9]{1}" />
    <xsd:pattern value="[0-9]{2}" />
    <xsd:pattern value="[0-9]{3}" />
    <xsd:pattern value="[0-9]{4}" />
    <xsd:pattern value="[0-9]{5}" />
    <xsd:pattern value="[0-9]{6}" />
    <xsd:pattern value="[0-9]{7}" />
    <xsd:pattern value="[0-9]{8}" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    </xsd:sequence>
    </xsd:complexType>
    </xsd:element>
    <xsd:element name="HMO_WEBSITE_ADDRESS">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="1" />
    <xsd:maxLength value="100" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="HMO_DAILY_CONTACT_EMAIL_ADDRESS">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="1" />
    <xsd:maxLength value="50" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="HMO_MONTHLY_CONTACT_EMAIL_ADDRESS">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="1" />
    <xsd:maxLength value="50" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="NPI">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[0-9]{1}" />
    <xsd:pattern value="[0-9]{2}" />
    <xsd:pattern value="[0-9]{3}" />
    <xsd:pattern value="[0-9]{4}" />
    <xsd:pattern value="[0-9]{5}" />
    <xsd:pattern value="[0-9]{6}" />
    <xsd:pattern value="[0-9]{7}" />
    <xsd:pattern value="[0-9]{8}" />
    <xsd:pattern value="[0-9]{9}" />
    <xsd:pattern value="[0-9]{10}" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="FIRST_NAME">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="1" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="LAST_NAME">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="1" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="MIDDLE_INITIAL">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="0" />
    <xsd:maxLength value="1" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="GENDER">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="0" />
    <xsd:maxLength value="1" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="LINE_1_ADDRESS">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="1" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="LINE_2_ADDRESS">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="0" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="CITY">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="1" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="STATE">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[a-zA-Z][a-zA-Z]" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="ZIP">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[0-9]{5}" />
    <xsd:pattern value="[0-9]{9}" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="COUNTY">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[0-9]{1}" />
    <xsd:pattern value="[0-9]{2}" />
    <xsd:pattern value="[0-9]{3}" />
    <xsd:pattern value="" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="PHONE_NUMBER">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[0-9]{10}" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="CLINIC_NAME">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="0" />
    <xsd:pattern value="" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="CLINIC_TYPE">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:minLength value="0" />
    <xsd:pattern value="" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="CLINIC_NPI">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[0-9]{1}" />
    <xsd:pattern value="[0-9]{2}" />
    <xsd:pattern value="[0-9]{3}" />
    <xsd:pattern value="[0-9]{4}" />
    <xsd:pattern value="[0-9]{5}" />
    <xsd:pattern value="[0-9]{6}" />
    <xsd:pattern value="[0-9]{7}" />
    <xsd:pattern value="[0-9]{8}" />
    <xsd:pattern value="[0-9]{9}" />
    <xsd:pattern value="[0-9]{10}" />
    <xsd:pattern value="" />
    <xsd:whiteSpace value="collapse"/>
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="PROVIDER_OFFICE_HOURS_TENTHS">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[0-9]{1}" />
    <xsd:pattern value="[0-9]{2}" />
    <xsd:pattern value="" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="MAXIMUM_PATIENTS">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[0-9]{1}" />
    <xsd:pattern value="[0-9]{2}" />
    <xsd:pattern value="[0-9]{3}" />
    <xsd:pattern value="[0-9]{4}" />
    <xsd:pattern value="" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="ACCEPT_NEW_PATIENT">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[A-Z]{1}" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="PRIMARY_CARE_INDICATOR">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[A-Z]{1}" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    <xsd:element name="FACILITY_NUM">
    <xsd:simpleType>
    <xsd:restriction base="xsd:string">
    <xsd:pattern value="[0-9]{1}" />
    <xsd:pattern value="[0-9]{2}" />
    <xsd:pattern value="[0-9]{3}" />
    <xsd:pattern value="[0-9]{4}" />
    <xsd:pattern value="[0-9]{5}" />
    <xsd:pattern value="[0-9]{6}" />
    <xsd:pattern value="[0-9]{7}" />
    <xsd:pattern value="[0-9]{8}" />
    <xsd:pattern value="[0-9]{9}" />
    <xsd:pattern value="[0-9]{10}" />
    <xsd:pattern value="" />
    <xsd:whiteSpace value="collapse" />
    </xsd:restriction>
    </xsd:simpleType>
    </xsd:element>
    </xsd:schema>
    Here's a sample of the XML (significantly shortened, and names and IDs changed to protect the innocent). BTW, the XML validates cleanly against the schema definition:
    <?xml version="1.0" encoding="UTF-8" standalone="no"?>
    <HMO DATE="03/26/2010">
    <HMO_GENERAL_INFORMATION>
    <MCO_ID_LIST>
    <MCO_ID>11111111</MCO_ID>
    </MCO_ID_LIST>
    <HMO_WEBSITE_ADDRESS>HTTP://WWW.SOMEHMONAME.COM</HMO_WEBSITE_ADDRESS>
    <HMO_SPECIAL_SERVICES>
    <CODE>00</CODE>
    </HMO_SPECIAL_SERVICES>
    <HMO_DAILY_CONTACT_EMAIL_ADDRESS>somename@someurl</HMO_DAILY_CONTACT_EMAIL_ADDRESS>
    <HMO_MONTHLY_CONTACT_EMAIL_ADDRESS>somename@someurl</HMO_MONTHLY_CONTACT_EMAIL_ADDRESS>
    </HMO_GENERAL_INFORMATION>
    <PROVIDERS RECORDS="1011">
    <PROVIDER>
    <NPI>1111111111</NPI>
    <FIRST_NAME>JOHN</FIRST_NAME>
    <LAST_NAME>DOE</LAST_NAME>
    <MIDDLE_INITIAL>A</MIDDLE_INITIAL>
    <GENDER>M</GENDER>
    <LINE_1_ADDRESS>1111 Some Rd</LINE_1_ADDRESS>
    <LINE_2_ADDRESS> </LINE_2_ADDRESS>
    <CITY>NOWHERE</CITY>
    <STATE>YN</STATE>
    <ZIP>12345</ZIP>
    <COUNTY>13</COUNTY>
    <PHONE_NUMBER>1111111111</PHONE_NUMBER>
    <CLINIC_NAME>SOME CLINIC - CORPORATE OFFICE</CLINIC_NAME>
    <CLINIC_NPI/>
    <ACCEPT_NEW_PATIENT>Y</ACCEPT_NEW_PATIENT>
    <PRIMARY_CARE_INDICATOR>N</PRIMARY_CARE_INDICATOR>
    <FOREIGN_LANGUAGES>
    <CODE> </CODE>
    </FOREIGN_LANGUAGES>
    <SPECIALTIES>
    <CODE>170</CODE>
    </SPECIALTIES>
    </PROVIDER>
    <PROVIDER>
    <NPI>2222222222</NPI>
    <FIRST_NAME>JANE</FIRST_NAME>
    <LAST_NAME>DOE</LAST_NAME>
    <MIDDLE_INITIAL>J</MIDDLE_INITIAL>
    <GENDER>F</GENDER>
    <LINE_1_ADDRESS>2222 SOMEOTHER ST</LINE_1_ADDRESS>
    <LINE_2_ADDRESS> </LINE_2_ADDRESS>
    <CITY>MYTOWN</CITY>
    <STATE>YN</STATE>
    <ZIP>12345</ZIP>
    <COUNTY>13</COUNTY>
    <PHONE_NUMBER>2222222222</PHONE_NUMBER>
    <CLINIC_NAME>SOME CLINIC - MYTOWN</CLINIC_NAME>
    <CLINIC_NPI/>
    <ACCEPT_NEW_PATIENT>Y</ACCEPT_NEW_PATIENT>
    <PRIMARY_CARE_INDICATOR>N</PRIMARY_CARE_INDICATOR>
    <FOREIGN_LANGUAGES>
    <CODE> </CODE>
    </FOREIGN_LANGUAGES>
    <SPECIALTIES>
    <CODE>322</CODE>
    <CODE>329</CODE>
    </SPECIALTIES>
    </PROVIDER>
    </PROVIDERS>
    <FACILITIES RECORDS="2">
    <FACILITY_NUM>1000000001</FACILITY_NUM>
    <FACILITY_NUM>2000000002</FACILITY_NUM>
    </FACILITIES>
    </HMO>
    As you can see, the SPECIALTIES node can contain more than one CODE value, si I can't use extractValue to retrieve them. Again, I need to extract the NPI value from the PROVIIDER node, and associate it with each of the CODE values from the SPECIALTIES node. So, what I would need to extract from this sample XML would be:
    NPI CODE
    1111111111 170
    2222222222 322
    2222222222 329
    This seems like it should be a pretty routine requirement, but I've tried everything I can think of (that is, everything I've learned to this point), and have not yet found a way............
    Ideally, the solution to extracting this data would utilize SQL (not PL/SQL, or Java, or XSL, etc) with XML extraction functions (e.g. extract, extractValue, XMLSequence, XMLTable, etc).
    Can anyone provide me with an example of how that iterative specialy code data could be extracted? Do I need to modify the .xsd to facilitate this extraction (so that registration of the schema results in other objects in the database)?
    Any suggestions or examples would be greatly appreciated.
    Thanks in advance, Dan
    P.S. - I hope the XML displays OK when I post this question!

    Hi,
    Thanks for your detailed sample, it's very helpful.
    This seems like it should be a pretty routine requirementIndeed, that's a classic (once you've got the method).
    So, here's how you can do it :
    SELECT x1.npi, x2.code
    FROM t,
         XMLTable(
          '/HMO/PROVIDERS/PROVIDER'
          passing t.doc
          columns
            npi number path 'NPI',
            specialties xmltype path 'SPECIALTIES'
         ) x1,
         XMLTable(
          'SPECIALTIES/CODE'
          passing x1.specialties
          columns
            code number path '.'
         ) x2
    ;Assuming the XML is stored in column T.DOC.
    As you see, for each NPI, the trick is to pass the entire SPECIALTIES node (kind of a join) to another nested XMLTable so that each CODE could be extracted as well.
    There's another method using only one XMLTable and a little more complex XQuery. I'll try to post it soon.
    HTH.
    Edit : 2nd method
    SELECT x.*
    FROM t,
         XMLTable(
          'for $i in /HMO/PROVIDERS/PROVIDER/SPECIALTIES/CODE
           return element e
            attribute npi { $i/../../NPI },
            $i/text()
          passing t.doc
          columns
            npi  number path '@npi',
            code number path '.'
         ) x
    ;Edited by: odie_63 on 27 mai 2010 18:43

Maybe you are looking for

  • Solaris 10: Unable to route to Internet

    Folks, I installed Solaris 10 on Sun Ultra 30. Server is up & everything looks good, except I am not able to connect to Internet from Ultra30. Problem is not in Name Resolution, but in routing to external network. At least it so seems. At my home, it

  • E66 Loses date and time.

    I set an alarm for work days. I switched the phone off with the alarm set. The alarm did not ring, but the display light flashed a couple of times at the approriate alarm time and then nothing .. No alarm. I swithced the phone on, it immediately asks

  • IPod dosen't seem to charge

    My iPod Video 60GB dosen't seem to charge anymore, no water damage and I haven't dropped it. Hooking it up to my PC or to the wall charger does really nothing all I get is a message saying please wait very low battery, I let it charge for hours and t

  • ACROBAT FILES NOT LAUNCHING

    I have recently upgraded to Acrobat Pro in CS6 to run on Lion. When I double click the PDF icon the files will not launch. I have been into 'info' and it is set to open. Any ideas welcome ? ? ? ? Barry

  • Sun Identity Manger 8.0 and fail over..

    We are setting up a fail/recovery site for our Sun Identity Manager solution, I had pictured a seem less fail over, but that looks near impossible to do with oracle database. I had pictured load balanced Appserver, with load balanced data bases, sort