XMLSequence to XMLTable

Hello!

I need assistance with XMLTable instead of XMLSequence.

It's the part of my XML.
         <emiDocAnt>
            <owner>11111111111111</owner>
            <idDocAnt>
              <idDocAntPap>
                <tpDoc>01</tpDoc>
              </idDocAntPap>
              <idDocAntPap>
                <tpDoc>02</tpDoc>
              </idDocAntPap>
            </idDocAnt>
            <idDocAnt>
              <idDocAntPap>
                <tpDoc>03</tpDoc>
              </idDocAntPap>
              <idDocAntPap>
                <tpDoc>04</tpDoc>
              </idDocAntPap>
            </idDocAnt>
          </emiDocAnt>
          <emiDocAnt>
            <owner>22222222222222</owner>
            <idDocAnt>
              <idDocAntPap>
                <tpDoc>05</tpDoc>
              </idDocAntPap>
              <idDocAntPap>
                <tpDoc>06</tpDoc>
              </idDocAntPap>
            </idDocAnt>
          </emiDocAnt>
I have this statement that works very well, it returns under the data within the Group of idDocAntPap and its owner.
SELECT EXTRACTVALUE(VALUE(vw),'/emiDocAnt/owner'),
       EXTRACTVALUE(VALUE(vw3), '/idDocAntPap/tpDoc')
  FROM tb_projCargaTMP,
  TABLE(XMLSequence(EXTRACT(XMLAutorizacao,'/emiDocAnt'))) vw,
  TABLE(XMLSequence(EXTRACT(vw.column_value,'//idDocAnt'))) vw2,
  TABLE(XMLSequence(EXTRACT(vw2.column_value,'//idDocAntPap'))) vw3;
But I would use XMLTable instead of XMLSequence. The problem is: How can I get the value of "owner"?
SELECT vw."owner",
       vw."tpDoc"
  FROM tb_projCargaTMP,
  XMLTABLE('/emiDocAnt/idDocAnt/idDocAntPap'
           PASSING tb_CargaTMP.XMLAutorizacao
           COLUMNS "owner" NUMBER(14)     PATH ???, <-- How can I get the owner value?
                   "tpDoc" NUMBER(2)      PATH '/idDocAntPap/tpDoc',
                   "serie" VARCHAR2(3)    PATH '/idDocAntPap/serie',
                   "subserie" VARCHAR2(2) PATH '/idDocAntPap/subser',
                   "nDoc" NUMBER(20)      PATH '/idDocAntPap/nDoc',
                   "dEmi" DATE            PATH '/idDocAntPap/dEmi'
           ) vw;
Thank you!!!

Based on a similar question to {message identifier: = 4093475}, you have two options, depending on whether you want to use XQuery or not within XMLTable.

WITH tb_projCargaTMP AS
(SELECT XMLTYPE('
            11111111111111
            
              
                01
              
              
                02
              
            
            
              
                03
              
              
                04
              
            
          
          
            22222222222222
            
              
                05
              
              
                06
              
            
          ') XMLAutorizacao -- added root node to make valid XML
   FROM dual)
SELECT vw.owner, vw2.*
  FROM tb_projCargaTMP,
  XMLTable('/root/emiDocAnt'
           PASSING tb_projCargaTMP.XMLAutorizacao
           COLUMNS
           owner      NUMBER(14)  PATH 'owner',
           antPapXML  XMLTYPE     PATH 'idDocAnt/idDocAntPap') vw,
  XMLTABLE('/idDocAntPap'
           PASSING vw.antPapXML
           COLUMNS
           tpDoc NUMBER(2)      PATH 'tpDoc',
           serie VARCHAR2(3)    PATH 'serie',
           subserie VARCHAR2(2) PATH 'subser',
           nDoc NUMBER(20)      PATH 'nDoc',
           dEmi DATE            PATH 'dEmi'
           ) vw2; 

and

SELECT vw.*
  FROM tb_projCargaTMP,
  XMLTable('for $i in /root/emiDocAnt/idDocAnt/idDocAntPap
              return element r{$i/../../owner,
                               $i/tpDoc,
                               $i/serie}'  -- continue on
           PASSING tb_projCargaTMP.XMLAutorizacao
           COLUMNS
           owner      NUMBER(14)  PATH 'owner',
           tpDoc NUMBER(2)        PATH 'tpDoc',
           serie VARCHAR2(3)      PATH 'serie',
           subserie VARCHAR2(2)   PATH 'subser',
           nDoc NUMBER(20)        PATH 'nDoc',
           dEmi DATE              PATH 'dEmi') vw;

Tags: Oracle Development

Similar Questions

  • XMLSEQUENCE or XMLTABLE

    I'm XML file I have loaded like a BLOB, then converted into a XML_TYPE and converted into a CLOB

    I use the following SQL code to extract the data

    the table is imp_xml_file and the column is xml_xml
    select  
    x.xml_xml.extract('aircraft/brochure/part/partNumber/text()').getstringval() as partno,
    x.xml_xml.extract('aircraft/brochure/part/NSCM/text()').getstringval() as NCSM, 
    x.xml_xml.extract('aircraft/brochure/part/LCN/text()').getstringval() as LCN,
    x.xml_xml.extract('aircraft/brochure/part/zone/text()').getstringval() as PZONE,
    from imp_xml_file x,table(xmlsequence(extract(xml_xml, '/aircraft/brochure/part'))) d
    where id = p_id
    
    there are 7 records in the XML file 
    
    if i use table(xmlsequence(extract(xml_xml, '/aircraft/brochure/part'))) d
    
    it returns 7 rows and each column but all data is concatenated for each field  
    
    if i use table(xmlsequence(extract(xml_xml, '/aircraft/brochure/'))) d
    it returns 1 with all the fileds concatenated 
    
    this is the data
    <?xml version="1.0" standalone="yes" ?> 
    - <aircraft>
      <buildNumber>BS059</buildNumber> 
    - <brochure>
      <dataSource>Centre Fuselage EPC Handover Brochure</dataSource> 
      <autoGeneratePhysicalPartRecords>YES</autoGeneratePhysicalPartRecords> 
      <importSerialNumbersInstallationDates>YES</importSerialNumbersInstallationDates> 
    - <part>
      <NSCM>98441</NSCM> 
      <partNumber>743900-1</partNumber> 
      <serialNumber>EFA0276</serialNumber> 
      <LCN>X291211</LCN> 
      <zone>267</zone> 
      <logCardRequired>-</logCardRequired> 
      <installationDate>05/09/2008 00:00:00:000</installationDate> 
      </part>
    - <part>
      <NSCM>98441</NSCM> 
      <partNumber>743900-2</partNumber> 
      <serialNumber>EFA0276</serialNumber> 
      <LCN>X291111</LCN> 
      <zone>257</zone> 
      <logCardRequired>-</logCardRequired> 
      <installationDate>05/09/2008 00:00:00:000</installationDate> 
      </part>
    - <part>
      <NSCM>98441</NSCM> 
      <partNumber>743900-3</partNumber> 
      <serialNumber>EFA0272</serialNumber> 
      <LCN>X291226</LCN> 
      <zone>267</zone> 
      <logCardRequired>-</logCardRequired> 
      <installationDate>12/08/2008 00:00:00:000</installationDate> 
      </part>
    - <part>
      <NSCM>98441</NSCM> 
      <partNumber>743900-4</partNumber> 
      <serialNumber>EFA0271</serialNumber> 
      <LCN>X291126</LCN> 
      <zone>257</zone> 
      <logCardRequired>-</logCardRequired> 
      <installationDate>11/08/2008 00:00:00:000</installationDate> 
      </part>
    - <part>
      <NSCM>98441</NSCM> 
      <partNumber>743900-5</partNumber> 
      <serialNumber>EFA-0265</serialNumber> 
      <LCN>X291227</LCN> 
      <zone>267</zone> 
      <logCardRequired>-</logCardRequired> 
      <installationDate>24/07/2008 00:00:00:000</installationDate> 
      </part>
    - <part>
      <NSCM>98441</NSCM> 
      <partNumber>743900-6</partNumber> 
      <serialNumber>EFA-0263</serialNumber> 
      <LCN>X291127</LCN> 
      <zone>257</zone> 
      <logCardRequired>-</logCardRequired> 
      <installationDate>21/07/2008 00:00:00:000</installationDate> 
      </part>
    - <part>
      <NSCM>D1227</NSCM> 
      <partNumber>743900-7</partNumber> 
      <serialNumber>08060258</serialNumber> 
      <LCN>X212301</LCN> 
      <zone>274</zone> 
      <logCardRequired>-</logCardRequired> 
      <installationDate>01/08/2008 00:00:00:000</installationDate> 
      </part>
     </brochure>
      </aircraft>
    
    This is how the data is returned
    
    PARTNO     NCSM     LCN     PZONE
    
    743900-1743900-2743900-3743900-4743900-5743900-6743900-7     984419844198441984419844198441D1227     X291211X291111X291226X291126X291227X291127X212301     267257267257267257274
    743900-1743900-2743900-3743900-4743900-5743900-6743900-7     984419844198441984419844198441D1227     X291211X291111X291226X291126X291227X291127X212301     267257267257267257274
    743900-1743900-2743900-3743900-4743900-5743900-6743900-7     984419844198441984419844198441D1227     X291211X291111X291226X291126X291227X291127X212301     267257267257267257274
    743900-1743900-2743900-3743900-4743900-5743900-6743900-7     984419844198441984419844198441D1227     X291211X291111X291226X291126X291227X291127X212301     267257267257267257274
    743900-1743900-2743900-3743900-4743900-5743900-6743900-7     984419844198441984419844198441D1227     X291211X291111X291226X291126X291227X291127X212301     267257267257267257274
    743900-1743900-2743900-3743900-4743900-5743900-6743900-7     984419844198441984419844198441D1227     X291211X291111X291226X291126X291227X291127X212301     267257267257267257274
    743900-1743900-2743900-3743900-4743900-5743900-6743900-7     984419844198441984419844198441D1227     X291211X291111X291226X291126X291227X291127X212301     267257267257267257274
    Any help greatly appreciated, all the examples seem to cover only 1 card in the XMLTYPE and it works very well with 1 card!
    not with 1 > :-((

    Chris

    Published by: CJ Bell on November 29, 2011 11:23

    Published by: CJ Bell on November 29, 2011 11:24

    Hi Chris,

    That's what you want:

    select extractvalue(x.column_value, '/part/partNumber') as PARTNO,
           extractvalue(x.column_value, '/part/NSCM') as NCSM,
           extractvalue(x.column_value, '/part/LCN') as LCN,
           extractvalue(x.column_value, '/part/zone') as PZONE
    from imp_xml_file t
       , table(
           xmlsequence(
             extract(t.xml_xml, '/aircraft/brochure/part'))
         ) x
    where id = p_id
    ;
    

    What is your version of the database? (select * from version$ v)
    From 10.2, XMLTable can do the same and much more.

    I'm XML file I have loaded like a BLOB, then converted into a XML_TYPE and converted into a CLOB

    Once again, depending on your version, you can load your file directly into the table with an INSERT.

  • XMLTable performance vs TABLE (XMLSequence ())

    Hello world

    I encountered a problem which I hope I can find help with.

    He has a task to analyze a large XML text (~ 15 MB) and update a table based on it. So I created a procedure that takes a parameter of XMLType and does the job. Pretty simple. However, the thing is that if I use XMLTable, which is the preferred method to parse the XML, it runs for hours. Once I replace XMLTable with the method TABLE (XMLSequence ()), the procedure ends in less than two minutes on the same machine. Seems very strange to me.

    Any ideas what could be the cause of such a poor performance from XMLTable?
    Oracle version is 11.2.0.2.0

    H1. The table structure
    create table Points (
      member_id int not null,
      point_id int,
      country_numeric character(3),
      place national character varying(50),
      name national character varying(255),
      currencies national character varying(255),
      address national character varying(255),
      contact national character varying(40),
      contact_phone national character varying(40),
      details national character varying(255),
      enabled_date date,
      works national character varying(255),
      active character default 1 check (active in (0, 1)) not null,
      unique (member_id, point_id)
    );
    H1. XMLTable method
    runs for several hours, if the input parameter is long of ~ 15 MB
      create procedure update_Points (
        p_Points in xmltype
      ) as
      begin
        insert into Points (member_id, point_id, country_numeric, place, name, currencies, address, contact, contact_phone, details, enabled_date, works)
        select
          ap.member_id,
          ap.point_id,
          ap.country_numeric,
          ap.place,
          ap.name,
          ap.currencies,
          ap.address,
          ap.contact,
          ap.contact_phone,
          ap.details,
          to_date(ap.enabled_date, 'DD.MM.YYYY'),
          ap.works
        from
          xmltable('for $Point in /document/directory/reply[@type=''Points'']/data/row return element Point { attribute member_id { $Point/column[@col=''1'']/@value }, attribute point_id { $Point/column[@col=''2'']/@value }, attribute country_numeric { $Point/column[@col=''3'']/@value }, attribute place { $Point/column[@col=''4'']/@value }, attribute name { $Point/column[@col=''5'']/@value }, attribute currencies { $Point/column[@col=''6'']/@value }, attribute address { $Point/column[@col=''7'']/@value }, attribute contact { $Point/column[@col=''8'']/@value }, attribute contact_phone { $Point/column[@col=''9'']/@value }, attribute details { $Point/column[@col=''10'']/@value }, attribute enabled_date { $Point/column[@col=''11'']/@value }, attribute works { $Point/column[@col=''12'']/@value } }'
            passing p_Points
            columns
              member_id int path '@member_id',
              point_id int path '@point_id',
              country_numeric character(3) path '@country_numeric',
              place national character varying(50) path '@place',
              name national character varying(255) path '@name',
              currencies national character varying(255) path '@currencies',
              address national character varying(255) path '@address',
              contact national character varying(40) path '@contact',
              contact_phone national character varying(40) path '@contact_phone',
              details national character varying(255) path '@details',
              enabled_date character(10) path '@enabled_date',
              works national character varying(255) path '@works') ap;
      end;
    H1. Method table (XMLSequence ())
    2 minutes with the same input parameter
      create procedure update_Points (
        p_Points in xmltype
      ) as
      begin
        insert into Points (member_id, point_id, country_numeric, place, name, currencies, address, contact, contact_phone, details, enabled_date, works)
        select
          value(x).extract('row/column[@col=''1'']/@value').getStringVal() member_id,
          value(x).extract('row/column[@col=''2'']/@value').getStringVal() point_id,
          value(x).extract('row/column[@col=''3'']/@value').getStringVal() country_numeric,
          value(x).extract('row/column[@col=''4'']/@value').getStringVal() place,
          extractValue(value(x), '/row/column[@col=''5'']/@value') name,
          value(x).extract('row/column[@col=''6'']/@value').getStringVal() currencies,
          value(x).extract('row/column[@col=''7'']/@value').getStringVal() address,
          value(x).extract('row/column[@col=''8'']/@value').getStringVal() contact,
          value(x).extract('row/column[@col=''9'']/@value').getStringVal() contact_phone,
          value(x).extract('row/column[@col=''10'']/@value').getStringVal() details,
          to_date(value(x).extract('row/column[@col=''11'']/@value').getStringVal(), 'DD.MM.YYYY') enabled_date,
          value(x).extract('row/column[@col=''12'']/@value').getStringVal() works
        from
          table(xmlsequence(extract(p_Points, '/document/directory/reply[@type=''Points'']/data/row'))) x;
      end;
    H1. Small example of XML
    <?xml version="1.0"?>
    <document>
      <directory>
        <reply type="Points">
          <data>
            <row>
              <column col="1" value="0"></column>
              <column col="2" value=""></column>
              <column col="3" value="643"></column>
              <column col="4" value="Something"></column>
              <column col="5" value="&quot;Sample&quot;"></column>
              <column col="6" value=""></column>
              <column col="7" value="Blah"></column>
              <column col="8" value="Bar"></column>
              <column col="9" value="0123456789"></column>
              <column col="10" value=""></column>
              <column col="11" value="01.01.2010"></column>
              <column col="12" value=""></column>
            </row>
          </data>
        </reply>
      </directory>
    </document>
    Published by: 999663 on April 15, 2013 13:21

    Because you have them different tasks. With the XML Table, you create a game via the return of intermediate results. Why not use the same approach to Table (XMLSequence ()) as in

        select
          ap.member_id,
          ap.point_id,
          ap.country_numeric,
          ap.place,
          ap.name,
          ap.currencies,
          ap.address,
          ap.contact,
          ap.contact_phone,
          ap.details,
          to_date(ap.enabled_date, 'DD.MM.YYYY'),
          ap.works
        from
          xmltable('/document/directory/reply[@type=''Points'']/data/row'
            passing p_Points
            columns
              member_id int path 'column[@col="1"]/@value',
              point_id int path 'column[@col="2"]/@value',
              country_numeric character(3) path 'column[@col="3"]/@value',
              place national character varying(50) path 'column[@col="4"]/@value',
              name national character varying(255) path 'column[@col="5"]/@value',
              currencies national character varying(255) path 'column[@col="6"]/@value',
              address national character varying(255) path 'column[@col="7"]/@value',
              contact national character varying(40) path 'column[@col="8"]/@value',
              contact_phone national character varying(40) path 'column[@col="9"]/@value',
              details national character varying(255) path 'column[@col="10"]/@value',
              enabled_date character(10) path 'column[@col="11"]/@value',
              works national character varying(255) path 'column[@col="12"]/@value') ap;
    

    I hope it works now as fast as the old method, but you will need to provide the statistics on that. I'm interested to see the moment of execution.

    Now if you want it to run faster, then

    CREATE TABLE xml_hold (xml_col xmltype);  -- can be a global temporary table if you desire
    

    and in your code

    INSERT INTO xml_hold VALUES (p_points);
    

    then change select it above to

        from xml_hold xh
          xmltable('/document/directory/reply[@type=''Points'']/data/row'
            passing xh.xml_col
    

    This works because the default storage for XMLType columns in 11.2.0.2 was replaced by SECUREFILE XML BINARY. When you store XML in this column, Oracle preprocesses the XML file and stores the data in a binary format that is more effective to deal with. You can read about that in the Oracle documentation if you wish. Even with the charge to convert the XML into an internal format, the whole processing time should be faster given the application can now run much more efficiently.

  • Order items TABLE (XMLSEQUENCE (Extract (...)))

    Hello

    I inherited a piece of SQL, extract information from an XMLTYPE column and I have a problem with the order of the returned items.

    My XML looks like this:

    < recommendation > < row >... < / line > < row >... < / Line > etc. < / recommendation >

    This is a comment and is divided into several lines (a limitation of the source system).

    I want to read the contents of each line and save it in a VARCHAR2 field but I want to keep the original order of the < row > elements to have a message with a sense in the end, beside the text I want to store a "Line number" column

    To make this work, I got something like this:

    SELECT

    a.ID,

    Extract (value (Rec), 'Line') online.

    ROW_NUMBER() over (PARTITION BY a.id ORDER BY null) as line_number

    Loads of table_with_the_id_to_process,

    table_with_my_XML has,

    REC TABLE (XMLSEQUENCE (EXTRACT (a.xmltext, ' / / recommendation/Line ')))

    WHERE a.id = loads.id

    It worked fine with 2-3 rows during the tests, but when running on real data (250-300 lines with XML fields) "line_number" become a bit at random: always start at 1 and go up until the number of element < row >, the order is as randomly, so my comments doesn't have a logical sense if I retrieve ordered them to "line_number.

    Any idea on how to get the <>the position of number or something else to calculate my column "line_number?

    Maybe I missed in the doc and Google simply because using bad language of research, so I'm open to any suggestion or idea.

    Thank you

    Gianni,

    What is your version of the database?

    The construction of the TABLE/XMLSequence has been deprecated in 11.2 for the function XMLTABLE.

    XMLTABLE is available from version 10.2 and has a clause for ORDINALITE to generate the sequence of required integer.

    You can also rebuild the entire message in a single VARCHAR2 or CLOB (depending on the size) and get rid of these line numbers.

  • Use of xmltable

    Hello

    I have the following XML in the tmp_xml of the tmp_table table column:

    " < = xmlns:env env:Envelope ' http://schemas.xmlsoap.org/SOAP/envelope/ ">

    < env:Header / >

    < env:Body >

    " < its: getCriteriaNamesListResponse xmlns: its = ' http://session.kernel.CMP.com/ ">

    < return >

    < element > CRITERIA_UID < / item >

    < element > CRITERIA_LAST_NAME < / item >

    < element > CRITERIA_MEXI_ADDRESS < / item >

    < element > CRITERIA_FIRST_NAME < / item >

    < element > NONE < / item >

    < element > CRITERIA_NISS < / item >

    < element > CRITERIA_INAMI < / item >

    < / return >

    < / its: getCriteriaNamesListResponse >

    < / env:Body >

    < / env:Envelope >

    I want to extract all the sequences of the "point".

    This selection back 1 line empty:

    Select extractvalue (value (b), ' / env:Envelope / env:Body / / return/point ',' xmlns:env = 'http://schemas.xmlsoap.org/soap/envelope/' ", xmlns: its ="http://session.kernel.mexi.com/"'") point

    tmp_table, a table (xmlsequence (extract (a.tmp_xml, ' / / return'))) b

    The select statement returns 7 blank lines:

    Select article extractvalue (value (b), ' / back/item ")

    tmp_table, a table (xmlsequence (extract (a.tmp_xml, ' / env:Envelope / env:Body / / return/point ',' xmlns:env = "http://schemas.xmlsoap.org/soap/envelope/", xmlns: its = "http://session.kernel.mexi.com/"'))) b


    Could someone give me a tip how to retrieve the values of 'element '?

    Best regards, Hans

    Looks like you hit an old bug in 10g.

    Try with the CURSOR_SHARING_EXACT indicator:

    Select / * + CURSOR_SHARING_EXACT * / x.*

    of tmp_table t

    xmltable)

    XmlNamespaces)

    "http://schemas.xmlsoap.org/soap/envelope/" as "env".

    , 'http://session.kernel.cmp.com/' as 'his '.

    )

    , ' / env:Envelope / env:Body / its: getCriteriaNamesListResponse/return/point '

    in passing t.tmp_xml

    varchar2 columns (30) the point road '.'

    ) x ;

    or you can also go back to the old method (now obsolete in Oracle 11 and following):

    SQL > select extractvalue (value (x), 'point') as element

    tmp_table 2 t

    3, table)

    4 xmlsequence)

    5. extract)

    6 t.tmp_xml

    7, ' / env:Envelope / env:Body / its: getCriteriaNamesListResponse/return/point '

    "' 8, ' xmlns:env ="http://schemas.xmlsoap.org/soap/envelope/"

    "9 xmlns: its ="http://session.kernel.cmp.com/' "."

    10           )

    11         )

    (12) x;

    AGENDA

    --------------------------------------------------------------------------------

    CRITERIA_UID

    CRITERIA_LAST_NAME

    CRITERIA_MEXI_ADDRESS

    CRITERIA_FIRST_NAME

    NONE

    CRITERIA_NISS

    CRITERIA_INAMI

    7 selected lines

  • ExtractValue, extracted, xmlsequence

    Could someone explain what extractvalue, xmlsequence and excerpt 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 step by step explanations. for example, what actually GETS back for the first and second rows?
    the code in the table and the data is the following:
    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:
    for example, if the first row not contained that single product/Notebook (as the second row) there is need to use TABLE (XMLSEQUENCE...), right? Only extractvalue (demo_field, "Product/Notebook/@Brand") would suffice, right? xmlsequence is necessary because the first line has several entrances laptop and all these multiple information is always returned as a bunch of items for laptop (knots?) instead of relational lines, is that correct? then xmlsequence comes into play in order to convert every book of this bunch of laptops in topics separated more later converted into relational lines by SCOREBOARD operator. is it more correct?

    Thank you

    Yep, that sounds about right.

    With XMLTABLE, it would be something like this...

    SQL> ed
    Wrote file afiedt.buf
    
      1  select x.*
      2  from   prod_xml_tab
      3        ,xmltable('/Product/Notebook'
      4                  passing prod_xml_tab.demo_field
      5                  columns Brand        varchar2(10) path './@Brand'
      6                         ,Model        varchar2(30) path './@Model'
      7                         ,Harddisk     varchar2(10) path './Harddisk'
      8                         ,Processor    varchar2(15) path './Processor'
      9                         ,RAM          varchar2(10) path './RAM'
     10                         ,Price        number       path './Price'
     11                         ,Display_Type varchar2(5)  path './Display/@Type'
     12                         ,Display_Size varchar2(5)  path './Display/@MonitorSize'
     13                         ,Weight       number       path './Weight'
     14*                ) x
    SQL> /
    
    BRAND      MODEL                          HARDDISK   PROCESSOR       RAM             PRICE DISPL DISPL     WEIGHT
    ---------- ------------------------------ ---------- --------------- ---------- ---------- ----- ----- ----------
    HP         Pavilion dv6-3132TX Notebook   640 GB     Intel Core i7   4 GB             1189 LED   15.6        4.14
    HP         HP Pavilion dv6-3032TX Noteboo 640 GB     Intel Core i7   6 GB             1104 LED   15.6         4.1
    HP         Pavilion dv6-3079TX Notebook   500 GB     Intel Core i7   4 GB             1099 LED   15.6        4.14
    Toshiba    Satellite A660/07R 3D Notebook 640 GB     Intel Core i7   4 GB             1444 LED   15.6        4.88
    
  • error ORA-03113 with XMLTABLE inside the subquery or view

    I get ORA-03113 error if I use a XMLTABLE result within one subquery of another query (if XMLTABLE inline or view). Code below to reproduce that - simplified and now rather meaningless - but produces the same error. Someone at - he seen this error re. XMLTABLE or know bugs in metalink on that? I couldn't find anything. I'll have to use deprecated table (xmlsequence) instead, which does not receive this error.


    -TABLE DROP TEST
    CREATE TABLE TEST (ID number (10), CUST_REF varchar2 (50 char), XMLDATA XMLTYPE);

    INSERT INTO TEST (ID, CUST_REF, XMLDATA) VALUES (1, 'XYZ',
    XMLTYPE ("<?") XML version = "1.0" encoding ="utf-16"? >
    < TESTXML
    xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance".
    xmlns = "urn: ABC - 123:TESTXML" >
    < collection >
    < TRANSACTION_COLLECTION >
    < TRANSACTION >
    < RECORD_ID > 1 < / RECORD_ID >
    < TRANSACTION_ID > 7791786 < / TRANSACTION_ID >
    < AMOUNT > 335 < / AMOUNT >
    < TYPE > I < / TYPE >
    DR < DC > < /DC >
    < / TRANSACTION >
    < / TRANSACTION_COLLECTION >
    < / collections >
    ((< / TESTXML > '));

    COMMIT;

    CREATE VIEW TEST_XMLVIEW
    AS
    SELECT
    ID,
    CUST_REF,
    xmltbl. RECORD_ID,
    xmltbl. TRANSACTION_ID,
    xmltbl. AMOUNT,
    xmltbl. TYPE,
    xmltbl. DC
    OF THE TEST,
    XMLTable (XMLNamespaces (DEFAULT "urn: ABC - 123:TESTXML'"),)
    "/ TESTXML/collections/TRANSACTION_COLLECTION/TRANSACTION" TEST PASSING. XMLDATA
    COLUMNS
    "RECORD_ID" number (10) path "RECORD_ID."
    "TRANSACTION_ID" VARCHAR (200 CHAR) PATH "TRANSACTION_ID"
    "DC' VARCHAR (200 CHAR) PATH"DC. "
    "TYPE' VARCHAR (200 CHAR) PATH"TYPE. "
    ('AMOUNT' NUMBER (38.8) PATH 'QUANTITY')
    AS xmltbl;


    WITH SUM_AMOUNTS (ID, CUST_REF, SUM_1, SUM_2, SUM_3)
    AS
    (SELECT ID, CUST_REF, FLAT AS FLAT AS SUM_2, FLAT + FLAT AS SUM_3, SUM_1)
    OF TEST_XMLVIEW
    GROUP BY ID, CUST_REF)
    Select
    ID,
    CUST_REF,
    SUM_1,
    SUM_2,
    SUM_3
    of SUM_AMOUNTS;


    Version information:
    Oracle Database 11 g Enterprise Edition Release 11.2.0.2.0 - 64 bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE Production 11.2.0.2.0
    AMT for 64-bit Windows: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production

    Someone at - he seen this error re. XMLTABLE or know bugs in metalink on that? I couldn't find anything.

    Really?

    Go to the directory path and look for the relevant trace or incident file.
    On my system, I can see something like this:

    ORA-07445: exception encountered: core dump [evaopn3()+656] [ACCESS_VIOLATION] [ADDR:0x0] [PC:0x234A5B6] [UNABLE_TO_READ] []
    

    Copy / paste this line into the ORA-00600/ORA-07445 on My Oracle Support search tool and search for your version.
    Read this article:

    * ORA-7445 (evaopn3) [860969.1 ID] *.

    and at the bottom of the page, among the associated bugs known, this one:

    Bug 12724375 : ORA-7445 [evaopn3] XQuery with GROUP BY *.

  • 10g XMLTABLE - can I return col XMLTYPE as well as retrieve specific columns

    Hello

    (This is for version 10.2.0.4)

    Currently, we have a giant XML column that contains many pieces to it. Divide us those in different parties through XMLSEQUENCE and then go to extract information from the other two XMLTYLE columns. I wish I could use XMLTABLE to reach the XMLTYPE columns to each other in a SQL statement, because I think it should be more effective. (We will have problems when the large XML column has 400 or more parts in - closure and do extract the values in two columns of xmltype + 400 times turns out to be slow going!)

    Anyway, I want to do is use XMLTABLE to produce a table for each column-shaped structure, then join them if this 1st part of col1 = part 1 in col2 = 1st party to col3.

    I looked around the documentation and google, but I'm stuck at a particular point: I would like to return XMLTYPE as values extracted from this XMLTYPE in the XMLTABLE on each column. I can't find a way to do it.

    Here is an example (that I got from http://thinktibits.blogspot.com/2011/03/oracle-xmltable-example-part-1.html) that hopefully will explain more clearly what I want to do, taking a column starting with:
    CREATE TABLE xml_test
    (NOTEBOOK XMLTYPE);
    
    insert into xml_test values ('<?xml version="1.0" encoding="UTF-8"?><Product Type=''Laptop''><Notebook Brand="HP" Model="Pavilion dv6-3132TX Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i7</Processor><RAM>4 GB</RAM></Notebook><Notebook Brand="HP" Model="HP Pavilion dv6-3032TX Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i7</Processor><RAM>6 GB</RAM></Notebook><Notebook Brand="Toshiba" Model="Satellite A660/07R 3D Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i7</Processor><RAM>4 GB</RAM></Notebook><Notebook Brand="Toshiba" Model="Satellite A660/15J Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i5</Processor><RAM>6 GB</RAM></Notebook></Product>');
    
    commit;
    
    SELECT NOTEBOOKS1.*
      FROM xml_test PO,
           XMLTable('//Notebook' PASSING PO.NOTEBOOK) notebooks1;
           
    COLUMN_VALUE                                                                                                                                           
    -------------------------------------------------------------------------------------------------------------------------------------------------------
    <Notebook Brand="HP" Model="Pavilion dv6-3132TX Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i7</Processor><RAM>4 GB</RAM></Notebook>
    <Notebook Brand="HP" Model="HP Pavilion dv6-3032TX Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i7</Processor><RAM>6 GB</RAM></Notebook>
    <Notebook Brand="Toshiba" Model="Satellite A660/07R 3D Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i7</Processor><RAM>4 GB</RAM></Notebook>
    <Notebook Brand="Toshiba" Model="Satellite A660/15J Notebook"><Harddisk>640 GB</Harddisk><Processor>Intel Core i5</Processor><RAM>6 GB</RAM></Notebook>
    
    4 rows selected.
    
    SELECT NOTEBOOKS2.*
      FROM xml_test PO,
           XMLTable('//Notebook' PASSING PO.NOTEBOOK
           COLUMNS  row_num for ordinality,
                    "BrandType"    CHAR(10) PATH '@Brand',
                    "ProductModel" CHAR(50) PATH '@Model',
                    "Harddisk" CHAR(10) PATH 'Harddisk',
                    "Processor" CHAR(20) PATH 'Processor',
                    "RAM" CHAR(10) PATH 'RAM') AS NOTEBOOKS2;
    
       ROW_NUM BrandType  ProductModel                                       Harddisk   Processor            RAM       
    ---------- ---------- -------------------------------------------------- ---------- -------------------- ----------
             1 HP         Pavilion dv6-3132TX Notebook                       640 GB     Intel Core i7        4 GB      
             2 HP         HP Pavilion dv6-3032TX Notebook                    640 GB     Intel Core i7        6 GB      
             3 Toshiba    Satellite A660/07R 3D Notebook                     640 GB     Intel Core i7        4 GB      
             4 Toshiba    Satellite A660/15J Notebook                        640 GB     Intel Core i5        6 GB      
    
    4 rows selected.
    What I would like is to have the first statement COLUMN_VALUE select content to appear as a column in the second selection - is this possible?

    In the worst case, I could join, only it generates a Cartesian product, because I do not know how to qualify the lines from the first XMLTABLE query (if I used the rownum in the query itself, that guarantee to come out in the same order as the XMLTABLE results? Would be part 1 always labeled tier 1, part 2, row2, etc.?).

    I hope this makes some kind of sense - I'm not on terms XML, unfortunately.

    ETA: If there is no way to achieve through XMLTABLE, is there any other way to reach him?

    Published by: Boneist on December 2, 2011 17:14

    Hello

    Define an additional XMLType projection in the clause of COLUMNS with PATH = '.' (the context item):

    SQL> set long 500
    SQL>
    SQL> SELECT x1.*
      2  FROM xml_test t
      3     , XMLTable('/Product/Notebook' PASSING t.notebook
      4         COLUMNS rn FOR ORDINALITY
      5               , BrandType      VARCHAR2(10) PATH '@Brand'
      6               , ProductModel   VARCHAR2(50) PATH '@Model'
      7               , Harddisk       VARCHAR2(10) PATH 'Harddisk'
      8               , Processor      VARCHAR2(20) PATH 'Processor'
      9               , RAM            VARCHAR2(10) PATH 'RAM'
     10               , NoteBook_node  XMLType      PATH '.'
     11       ) x1
     12  ;
    
            RN BRANDTYPE  PRODUCTMODEL                                       HARDDISK   PROCESSOR            RAM        NOTEBOOK_NODE
    ---------- ---------- -------------------------------------------------- ---------- -------------------- ---------- --------------------------------------------------------------------------------
             1 HP         Pavilion dv6-3132TX Notebook                       640 GB     Intel Core i7        4 GB       
                                                                                                                          640 GB
                                                                                                                          Intel Core i7
                                                                                                                          4 GB
                                                                                                                        
    
             2 HP         HP Pavilion dv6-3032TX Notebook                    640 GB     Intel Core i7        6 GB       
                                                                                                                          640 GB
                                                                                                                          Intel Core i7
                                                                                                                          6 GB
                                                                                                                        
    
             3 Toshiba    Satellite A660/07R 3D Notebook                     640 GB     Intel Core i7        4 GB       
                                                                                                                          640 GB
                                                                                                                          Intel Core i7
                                                                                                                          4 GB
                                                                                                                        
    
             4 Toshiba    Satellite A660/15J Notebook                        640 GB     Intel Core i5        6 GB       
                                                                                                                          640 GB
                                                                                                                          Intel Core i5
                                                                                                                          6 GB
                                                                                                                        
     
    

    I'm not sure that understand the rest of your condition.
    You want to still break through the XMLType generated in a set of relational lines, or repeat on different columns of the same base table?

  • XDB. XMLIndex problem and table (XMLSEQUENCE (EXTRACT (xmltype, path))

    Hello
    I have a database of Oracle 11 g Release 11.1.0.6.0 - 64 bit Production With the Real Application Clusters option.

    I feel something strange with an XMLType column.
    I have a table configurator.t_vehicle_configuration (id_vehicle x_configuration NUMBER, XMLType).
    x_configuration is unstructured.

    I created an index on the field of xml in this way:

    CREATE INDEX idx_vehicle_configuration ON configurator.t_vehicle_configuration (x_configuration) INDEXTYPE IS XDB. XMLIndex;

    Then I have a package implementing a function that count nodes in the xml field and its return values

    This does not (return 0 instead of 1):
        SELECT count(*)
          INTO count_
          FROM configurator.v_vehicle_configuration vc,
               table(XMLSEQUENCE(EXTRACT(vc.x_configuration, '/vehicleconf/GeoFence/spaceTarget[@id="'||in_id_space_target||'"]/user[@id="'||in_id_user||'"]/alarmwhen'))) p
         WHERE vc.id_vehicle = in_id_vehicle;
        
        RETURN count_;
    This mode of operation (return 1):
        str_ := '/vehicleconf/GeoFence/spaceTarget[@id="'||in_id_space_target||'"]/user[@id="'||in_id_user||'"]/alarmwhen';
    
        SELECT count(*)
          INTO count_
          FROM configurator.v_vehicle_configuration vc,
               table(XMLSEQUENCE(EXTRACT(vc.x_configuration,str_))) p
         WHERE vc.id_vehicle = in_id_vehicle;
        
        RETURN count_;
    As this mode of operation:
        SELECT /*+ NO_XMLINDEX_REWRITE */ count(*)
          INTO count_
          FROM configurator.v_vehicle_configuration vc,
               table(XMLSEQUENCE(EXTRACT(vc.x_configuration, '/vehicleconf/GeoFence/spaceTarget[@id="'||in_id_space_target||'"]/user[@id="'||in_id_user||'"]/alarmwhen'))) p
         WHERE vc.id_vehicle = in_id_vehicle;
        
        RETURN count_;
    And also this way it works:
        SELECT count(*)
          INTO count_
          FROM configurator.v_vehicle_configuration vc,
               table(XMLSEQUENCE(EXTRACT(vc.x_configuration, '/vehicleconf/GeoFence/spaceTarget[@id="228"]/user[@id="49"]/alarmwhen'))) p
         WHERE vc.id_vehicle = in_id_vehicle;
        
        RETURN count_;
    I sailed a bit on the internet but I have found no help for my problem...
    I guess that's something concerning the substitution on the fly of the variables, which does not work with an index.
    Do you have any suggestions?
    Is there a way that will prevent the rewriting of all the functions?

    Thanks in advance

    First

    On 11.1.0.6.0 Please do not use table (xmlsequence (extract ())) Please use the SQL/XML standard XMLTAble operator...

    SELECT COUNT(*)
       INTO count_
      FROM configurator.v_vehicle_configuration vc,
               XMLTABLE
              (
                  '$XML/vehicleconf/GeoFence/spaceTarget[@id=$ID_SPACE_TARGET]/user[@id=$ID_USER]/alarmwhen'
                  passing vc.x_configuration as "XML",  in_id_space_target as "ID_SPACE_TARGET",  in_id_user as "ID_USER"
               )
         WHERE vc.id_vehicle = in_id_vehicle;
    
        RETURN count_;
    

    2. never generate XPATH strings dynamically (Note XMLTABLE simply will not allow it). It is almost impossible to optimize since in the case escalated, the query may be a function of the processing line, and it leaves the vulnerable application WHO the problems of injection. Earlier versions of XML DB supported the use of string concatenation technique to provide the value of predicate as a method of implementation of the bind variable, but from what I remember, this is only implemented and tested for storage relatiion object. Even when workng with storage relational object this technique should not be used in the development of new code n a 10.2.x post database. As far as I know this was not implemented for binary XML / XML INdex since the implementations of XMLQUERY, XMLTable and XMLEXists provided a much more robust implementation and standardized to link the underlying values at query runtime

    If you do not know the XPATH expression until run time please build the complete SQL statement dynamically and run it via EXECUTE IMMEDIATE or DBMS_SQL, then pay attention to injection vunerabilities in your application.

    The fact that you get different results seems to be the result of the previous method of binding of predicates works do not correctly with the XML Index. If the solution I gave above does not work, please fill out a bug and that we can continue the investigation

    Published by: mdrake on February 25, 2011 17:32

  • need help with query xmltable

    Hello team,

    I have a problem by querying the xml file. Unable to get the correct result.

    XML:

    " < = xmlns:env env:Envelope ' http://schemas.xmlsoap.org/SOAP/envelope/ "xmlns:wsa =" " http://www.w3.org/2005/08/addressing ">

    < env:Header >

    < wsa: MessageID > urn: 93D110E0D6CD11E5BF8FC7751D1F819E < / wsa: MessageID >

    < wsa: ReplyTo >

    < wsa:Address > http://www.w3.org/2005/08/addressing/anonymous < / wsa:Address >

    < / wsa: ReplyTo >

    < / env:Header >

    < env:Body >

    " < = xmlns:client retrieveSubscriberDetailResponse ' http://xmlns.Oracle.com/SBLMVNE/MVNERetrieveSubscriberDetail/MVNERetrieveSubscriberDetailProcess "xmlns =" http://xmlns.Oracle.com/SBLMVNE/MVNERetrieveSubscriberDetail/MVNERetrieveSubscriberDetailProcess ">

    < customer: header >

    < customer: InterfaceName / >

    < customer: InterfaceId / >

    < customer: CorrelationId > Interface Sync n / < / customer: CorrelationId >

    < customer: ResultCode > 0 < / customer: ResultCode >

    < customer: ResultDescription > success < / customer: ResultDescription >

    < / customer: header >

    < customer: subscribers >

    < customer: Subscriber >

    < customer: subscriberId > 3891907 < / customer: subscriberId >

    < customer: serviceNo1 > 639372000342 < / client: serviceNo1 >

    < customer: serviceNo2 / >

    < customer: serviceNo3 > 515024400960403 < / client: serviceNo3 >

    < customer: serviceNo4 >

    < / customer: Subscriber >

    < / customer: subscribers >

    < / retrieveSubscriberDetailResponse >

    < / env:Body >

    < / env:Envolope >

    Here's my query:

    Select x.* tmp_soap_data t,

    xmltable (xmlnamespaces ('http://schemas.xmlsoap.org/soap/envelope/"as"ns1","http://www.w3.org/2005/08/addressing"as"ns2", ))

                             ' ( http://xmlns.Oracle.com/SBLMVNE/MVNERetrieveSubscriberDetail/MVNERetrieveSubscriberDetailProcess ' as 'ns3'),

    ' ns1:Envelope / ns1:Body/retrieveSubscriberDetailResponse/ns3:subscribers '

    in passing t.lob_data

    path of columns subs_id varchar2 (100) ' / ns3:Subscriber / ns3:subscriberId') x;

    but the result is NULL.

    I'm on the right track with my request?

    Best regards

    Nelz Ki

    It works

    WITH tmp_soap_data as (select xmltype('
      
        
          
            
              3891907
              639372000342
              
              515024400960403
              
      
        
      
       
    ') lob_data from dual)
    -- Above is dummy setup to mimic your data tables
    select x.*
      from tmp_soap_data t,
           xmltable(xmlnamespaces('http://schemas.xmlsoap.org/soap/envelope/' as "ns1",
                                  'http://xmlns.oracle.com/SBLMVNE/MVNERetrieveSubscriberDetail/MVNERetrieveSubscriberDetailProcess' as "ns3"),
                    'ns1:Envelope/ns1:Body/ns3:retrieveSubscriberDetailResponse/ns3:subscribers/ns3:Subscriber'
                    passing t.lob_data
                    columns
                    subs_id varchar2(100) path 'ns3:subscriberId') x;
    

    You were close.

    I made several minor changes.  Been cut down XML to remove the nodes not used for readability, typos corrected in the node names, removed the namespace ns2 is not mentioned in the XPath expressions, changed XPath primary as assuming that the client node: Subscriber could repeat, changed the XPath for the subs_id accordingly noticed that the node retrieveSubscriberDetailResponse uses the same URI for two namespaces, has added the ns3 prefix to retrieveSubscriberDetailResponse in the Xpath expression since it resides is in a default namespace and prefix ns3 points to this default namespace.

  • Need help XMLTable/XMLQuery is Sub - XML

    < if someone can change this thread to the SQL group, I am unable to do > *.

    As part of the query below I need plus a column which shows the part price sup - xml values. Can someone help please get the required result?

    with Test_Table1 as (
      select XMLType('<Quote><Item><Name>1</Name><price>23</price></Item><Item><Name>2</Name><price>50</price></Item></Quote>')  as Object_Value from Dual union all
      select XMLType('<Quote><Item><Name>3</Name><price>100</price></Item></Quote>')   as Object_Value from Dual
    )
    select X.price
    from Test_Table1,
         xmltable('/Quote/Item' PASSING OBJECT_VALUE
                  COLUMNS
                     price PATH 'price') X
    ;
    

    Output

    ======

    23

    50

    100

    Power required

    ============

    Price Sub-XML
    23< item > < name > 1 < / name > < price > 23 < price / > < / Item >
    50< item > < name > 2 < / name > < price > 50 < price / > < / Item >
    100< item > < name > 3 < / name > < price > 100 < price / > < / Item >

    Thanks in advance for your support.

    You can access the context item is past the main XQuery expression using the '.' accessor (dot):

    Select X.*

    of Test_Table1.

    XMLTable ('/ quote/pos ' OBJECT_VALUE by the WAY)

    COLUMNS

    price PATH number 'price '.

    , point to xmltype path '.'

    ) X

    ;

  • XML tag is not acceptable to XMLTABLE

    Hi all

    I tried to query data at the bottom of XML

    <? XML version = "1.0" encoding = "gb2312"? >

    < ScanData >

    < BOXID BOX "8797" = "0J34897DA6115AXnZ5300F2M" create_time = LOTNO = ' 2015/9/22 14:26:06 ' hostname = "xnlrj" / >

    < BOXID BOX "8797" = "0J34897DA6115AXnZ5120M8Z" create_time = LOTNO = ' 2015/9/22 14:26:06 ' hostname = "xnlrj" / >

    < BOXID = "9999" = "0J34897DA6115AXnZ52900YF" create_time = LOTNO BOX "2015/9/22 15:05:33 ' hostname ="xnlrj"/ >

    < BOXID = "9999" = "0J34897DA6115AXLT53300A0" create_time = LOTNO BOX "2015/9/22 15:05:33 ' hostname ="xnlrj"/ >

    < BOXID = "9999" = "0J34897DA6115AXnZ5290339" create_time = LOTNO BOX "2015/9/22 15:05:33 ' hostname ="xnlrj"/ >

    < BOXID = "9999" = "0J34897DA6115AXnZ5120LK3" create_time = LOTNO BOX ' 2015/9/22 15:05:34 ' hostname = "xnlrj" / >

    < BOXID = "9999" = "0J34897DA6115AXnZ5110BD5" create_time = LOTNO BOX ' 2015/9/22 15:05:34 ' hostname = "xnlrj" / >

    < BOXID = "9999" = "0J34897DA6115AXnZ52905MH" create_time = LOTNO BOX ' 2015/9/22 15:05:34 ' hostname = "xnlrj" / >

    < / ScanData >

    using the query below, but I have to remove '<? xml version = "1.0" encoding = 'gb2312'? > ' otherwise it will ask the error.

    What is the default behavior of XMLTABLE?

    SELECT extractvalue(t.column_value,'/BOX/@BOXID') BOXID,UPPER(extractvalue(t.column_value,'/BOX/@LOTNO')) SN

    Of

    XMLTABLE)

    ' for $root in $scandata

    return $root/ScanData/BOX '

    from XMLTYPE (')

    <? XML version = "1.0" encoding = "gb2312"? >

    < ScanData >

    < BOXID BOX "8797" = "0J34897DA6115AXnZ5300F2M" create_time = LOTNO = ' 2015/9/22 14:26:06 ' hostname = "xnlrj" / >

    < BOXID BOX "8797" = "0J34897DA6115AXnZ5120M8Z" create_time = LOTNO = ' 2015/9/22 14:26:06 ' hostname = "xnlrj" / >

    < BOXID = "9999" = "0J34897DA6115AXnZ52900YF" create_time = LOTNO BOX "2015/9/22 15:05:33 ' hostname ="xnlrj"/ >

    < BOXID = "9999" = "0J34897DA6115AXLT53300A0" create_time = LOTNO BOX "2015/9/22 15:05:33 ' hostname ="xnlrj"/ >

    < BOXID = "9999" = "0J34897DA6115AXnZ5290339" create_time = LOTNO BOX "2015/9/22 15:05:33 ' hostname ="xnlrj"/ >

    < BOXID = "9999" = "0J34897DA6115AXnZ5120LK3" create_time = LOTNO BOX ' 2015/9/22 15:05:34 ' hostname = "xnlrj" / >

    < BOXID = "9999" = "0J34897DA6115AXnZ5110BD5" create_time = LOTNO BOX ' 2015/9/22 15:05:34 ' hostname = "xnlrj" / >

    < BOXID = "9999" = "0J34897DA6115AXnZ52905MH" create_time = LOTNO BOX ' 2015/9/22 15:05:34 ' hostname = "xnlrj" / >

    ((< / ScanData > ') AS 'scandata') t

    Thank you

    Vincent

    Vincent,

    using the query below, but I have to remove '' the case, he will ask error,

    In the face of an error, it is always useful to see what is the real error.

    In your example, it's because of the break line appearing before the prologue (thepart).

    Remove it and it should be OK.

    In addition, there is no point uses EXTRACTVALUE (discouraged) at the screening can be fully defined in the clause of COLUMNS:

    SELECT t.*
    FROM XMLTABLE (
           '/ScanData/BOX'
          passing XMLTYPE('
    
      
      
      
      
      
      
      
      
    ')
      columns boxid number       path '@BOXID'
            , sn    varchar2(30) path '@LOTNO'
    ) t ;
    
  • Empty query XMLTABLE results

    I can successfully submit the SOAP request, retrieve the expected answer, store the answer in the column of XMLTYPE table but attempt to stored query XML using XMLTABLE response returns 0 rows.  I looked through other forum on this subject entries, suspect the problem, it's something simple/syntactic, have tried many things to fix, but without success.   Any help would be greatly appreciated.   I tried to provide relevant details below.   Thanks in advance!

    Create the table with a column of type XMLTYPE to hold the SOAP call response:

    CREATE TABLE unfilled_ss

    (

    ID NUMBER,

    XMLTYPE data

    );

    Insert line in table created above with the answer of the function 'soap_call' as the value of the column of type XMLTYPE data:

    insert into unfilled_ss

    Select

    2,

    () soap_call

    ' < wsc:search >

    < arg0 >

    system of < user name > < / username >

    password <>systempassword < / password >

    <>criteria

    < DmsShipL and vacuum >

    < ShipmentHeader-ShipDate > > 10/07/2015 = < / ShipmentHeader-ShipDate >

    < ItemWarehouseMaster stock_item > Y < / ItemWarehouseMaster-stock_item >

    the territory < CustomerMaster > LMHS. CFHA; SMHS < / CustomerMaster-territory >

    < / DmsShipL and empty >

    < / criteria >

    < LignesMax > 2 < / LignesMax >

    < / arg0 >

    < / wsc:search > ',

    ' http://elite-app.leesar.com/prod_841/WS/WmsWebService ',

    ' http://elite-app.leesar.com/prod_841/WS/WmsWebService '

    )

    Double;

    Query the table above showing characters of the response XML "soap_call", inserted in the column of type XMLTYPE data:

    SELECT id, substr(data,1,160) 'FIRST_FEW_CHARS_OF_XMLDOC' from unfilled_ss where id = 2;

    ID FIRST_FEW_CHARS_OF_XMLDOC

    ---------- ----------------------------------------------------------------------------------------------------------------------------------------------------------------

    " 2 < envelope soap: xmlns:soap = ' http://schemas.xmlsoap.org/SOAP/envelope/ ">                                                                                          

    < soap: Body >

    < ns2:searchResponse xmlns:ns2 = "wsclient.wms.tecsys.com" >

    < return >

    Here's value for the column 'DATA' type response representing XMLTYPE SOAP appeal referenced above in full:

    " < envelope soap: xmlns:soap = ' http://schemas.xmlsoap.org/SOAP/envelope/ ">

    < soap: Body >

    < ns2:searchResponse xmlns:ns2 = "wsclient.wms.tecsys.com" >

    < return >

    < status >

    < code > 0 </postcode >

    < description > success < / description >

    < timestamp > 2015-07-10 10:45:16 < / timestamp >

    < / status >

    <>criteria

    < DmsShipL and vacuum >

    < ShipmentHeader-ShipDate > > 10/07/2015 = < / ShipmentHeader-ShipDate >

    < ItemWarehouseMaster stock_item > Y < / ItemWarehouseMaster-stock_item >

    the territory < CustomerMaster > LMHS. CFHA; SMHS < / CustomerMaster-territory >

    < / DmsShipL and empty >

    < / criteria >

    < LignesMax > 2 < / LignesMax >

    < result >

    < DmsShipL and vacuum >

    < ShipmentHeader-open > 1 < / open ShipmentHeader >

    < > 01 warehouse < / warehouse >

    < pps_num > 178625 < / pps_num >

    < ShipmentHeader DateAndTimePpsWasPrinted > 2015-07-09 09:31:03 < / ShipmentHeader-DateAndTimePpsWasPrinted >

    < LineNumber > 1 < / LineNumber >

    < KitComponentLineNumber > 0 < / KitComponentLineNumber >

    < element > 2002686 < / Item >

    < AllocatedQuantity > 6,000 < / AllocatedQuantity >

    < QuantityShippedInSellingUom > 0.000 < / QuantityShippedInSellingUom >

    < QuantityShipped > 0.000 < / QuantityShipped >

    < AssetItemQuantityReturned > 0.000 < / AssetItemQuantityReturned >

    < SellingUom > PK < / SellingUom >

    < ShipmentHeader-SalesOrderHeader-Order > 181035 < / ShipmentHeader-SalesOrderHeader-Order >

    < Client-SalesInvoiceHeader-ShipmentHeader > 355000 < / ShipmentHeader-SalesInvoiceHeader-client >

    < SalesOrderHeader-ShipmentHeader-CustomerPo > Lmackin < / SalesOrderHeader-ShipmentHeader-CustomerPo >

    PK < ItemMaster-StockingUom > < / ItemMaster-StockingUom >

    < WarehouseTransfer / >

    < TransferLine-ToWarehouse / >

    < TransferBackorder / >

    < ShipmentLineChargeGrid > 0 | 2254373 < / ShipmentLineChargeGrid >

    < CreatedOn > 2015-07-09 09:31:03 < / CreatedOn >

    TECSYS < CreatedBy > < / CreatedBy >

    < ModifiedOn > 2015-07-09 09:31:03 < / ModifiedOn >

    TECSYS < ModifiedBy > < / ModifiedBy >

    < VersionCounter > 1 < / VersionCounter >

    < / DmsShipL and empty >

    < DmsShipL and vacuum >

    < ShipmentHeader-open > 1 < / open ShipmentHeader >

    < > 01 warehouse < / warehouse >

    < pps_num > 178628 < / pps_num >

    < ShipmentHeader DateAndTimePpsWasPrinted > 2015-07-09 09:31:50 < / ShipmentHeader-DateAndTimePpsWasPrinted >

    < LineNumber > 57 < / LineNumber >

    < KitComponentLineNumber > 0 < / KitComponentLineNumber >

    < element > 2069220 < / Item >

    < AllocatedQuantity > 0.000 < / AllocatedQuantity >

    < QuantityShippedInSellingUom > 0.000 < / QuantityShippedInSellingUom >

    < QuantityShipped > 0.000 < / QuantityShipped >

    < AssetItemQuantityReturned > 0.000 < / AssetItemQuantityReturned >

    < SellingUom > RL < / SellingUom >

    < ShipmentHeader-SalesOrderHeader-Order > 181041 < / ShipmentHeader-SalesOrderHeader-Order >

    < Client-SalesInvoiceHeader-ShipmentHeader > 612000 < / ShipmentHeader-SalesInvoiceHeader-client >

    < SalesOrderHeader-ShipmentHeader-CustomerPo > 417096_612105 < / SalesOrderHeader-ShipmentHeader-CustomerPo >

    RL < ItemMaster-StockingUom > < / ItemMaster-StockingUom >

    < WarehouseTransfer / >

    < TransferLine-ToWarehouse / >

    < TransferBackorder / >

    < ShipmentLineChargeGrid > 0 | 2254481 < / ShipmentLineChargeGrid >

    < CreatedOn > 2015-07-09 09:31:50 < / CreatedOn >

    TECSYS < CreatedBy > < / CreatedBy >

    < ModifiedOn > 2015-07-09 09:31:50 < / ModifiedOn >

    TECSYS < ModifiedBy > < / ModifiedBy >

    < VersionCounter > 1 < / VersionCounter >

    < / DmsShipL and empty >

    < / result >

    dms_ship_l.unfilled < viewName > < / viewName >

    < / return >

    < / ns2:searchResponse >

    < / soap: Body >

    < / envelope soap: >

    Here's my problem - when I try to use XMLTABLE at end of the contents of the request of the column 'DATA' as query tabular data, completed without error but no lines are returned:

    with xml_table_data as

    (

    SELECT x.*

    Of e unfilled_ss,.

    XMLTABLE)

    xmlnamespaces ('http://schemas.xmlsoap.org/soap/envelope' as "SOAP", "wsclient.dms.tecsys.com" like "ns2"),

    ' /: soap envelope / soap: Body / ns2:searchResponse / back/result/DmsShipL-empty '

    PASSAGE e.data

    COLUMNS

    Varchar2 (50) warehouse PATH "/ DmsShipL/warehouse empty."

    VARCHAR2 (50) PATH of the pps_num ' / DmsShipL-empty/pps_num, "

    Point varchar2 (30) PATH ' / DmsShipL-vacuum/Item. "

    Varchar2 (50) PATH of the SellingUom ' / DmsShipL-vacuum/SellingUom.

    ) x

    where e.id = 2

    )

    Select count (*)

    of xml_table_data;

    COUNT (*)

    ----------

    0

    Thanks for the detailed test case.

    You have typos in the mapping of namespaces.

    Here's the good:

    XmlNamespaces)

    "http://schemas.xmlsoap.org/soap/envelope/" as "SOAP."

    ' wsclient. wms.tecsys.com' as "ns2.

    )

    SQL> SELECT  x.*
      2  FROM unfilled_ss e
      3     , XMLTABLE(
      4         XMLNamespaces(
      5           'http://schemas.xmlsoap.org/soap/envelope/' as "soap"
      6         , 'wsclient.wms.tecsys.com'  as "ns2"
      7         )
      8       , '/soap:Envelope/soap:Body/ns2:searchResponse/return/result/DmsShipL-Unfilled'
      9         PASSING e.data
     10         COLUMNS
     11           Warehouse  varchar2(50) PATH '/DmsShipL-Unfilled/Warehouse'
     12         , pps_num    varchar2(50) PATH '/DmsShipL-Unfilled/pps_num'
     13         , Item       varchar2(30) PATH '/DmsShipL-Unfilled/Item'
     14         , SellingUom varchar2(50) PATH '/DmsShipL-Unfilled/SellingUom'
     15       ) x
     16  WHERE e.id = 2 ;
    
    WAREHOUSE    PPS_NUM   ITEM     SELLINGUOM
    ------------ --------- -------- -------------
    01           178625    2002686  PK
    01           178628    2069220  RL
    
  • How to use XMLTable on XML encoded

    I have the case of the external web service providing the response is XML, which contains the XML encoded at the breast.

    I would use XMLTable to retrieve the results. I'm familiar with XMLTable, but cannot get to work with mixed coded/non-encoded XML. This returns no data.  If all non-coded, then returns required data. I guess I need to convert somehow, but don't know how to achieve this.

    Code snippet below


    declare
    vResponse XMLType;
    begin
    vResponse:= XMLTYPE(
    '<ValAddrResult>
    <Addresses>
    <item><Address>&lt;AddressLine1&gt;3 Smith Ct&lt;/AddressLine1&gt;</Address></item>
    <item><Address>&lt;AddressLine1&gt;4 Smith Ct&lt;/AddressLine1&gt;</Address></item>
    </Addresses>
    </ValAddrResult>');
    
      for c1 in
      (SELECT x.*
        FROM XMLTABLE ('/ValAddrResult/Addresses/item/Address'
                      passing vResponse
                      COLUMNS AddressLine1 VARCHAR2(500) PATH 'AddressLine1') x)
      loop
        dbms_output.put_line(c1.AddressLine1);
      end loop;
    end;
    
    

    Thank you

    I guess I need to convert somehow, but don't know how to achieve this.

    Exactly.

    You first need to extract the XML string encoded in a VARCHAR2/CLOB column (depending on the expected size).

    Example below uses a CLOB, but you must be at least on 11.2.0.2 full support.

    Then, in a second XMLTABLE, parse the XML string into an XMLType and extract the necessary information:

    SQL> set serveroutput on
    SQL>
    SQL> declare
      2    vResponse XMLType;
      3  begin
      4    vResponse:= XMLTYPE(
      5  '
      6  
      7  
    <AddressLine1>3 Smith Ct</AddressLine1>
    8
    <AddressLine1>4 Smith Ct</AddressLine1>
    9
    10
    '); 11 12 for c1 in ( 13 SELECT x2.* 14 FROM XMLTABLE( 15 '/ValAddrResult/Addresses/item' 16 passing vResponse 17 COLUMNS Address clob PATH 'Address' 18 ) x1 19 , xmltable( 20 '/AddressLine1' 21 passing xmlparse(content x1.address) 22 columns addressline1 varchar2(30) path '.' 23 ) x2 24 ) 25 loop 26 dbms_output.put_line(c1.AddressLine1); 27 end loop; 28 29 end; 30 / 3 Smith Ct 4 Smith Ct PL/SQL procedure successfully completed.
  • XMLTable query returns one line per element multiple

    Hello

    Using Oracle 11 g Release 2, I have a XML file that is stored in the following table:

    CREATE TABLE XML_FILES

    (

    FILENAME VARCHAR2 (1000).

    FILECONTENT XMLTYPE

    );

    The sample XML file:

    < includedClaimProcessingResult >

    < ClaimRecordIdentifier > 1000 < / ClaimRecordIdentifier >

    < ClaimIdentifier > 0x1ABC2D123456789 < / ClaimIdentifier >

    < classifyingProcessingStatusType >

    < statusCode > R < / statusCode >

    < / classifyingProcessingStatusType >

    < recordedError >

    Pharmacy claim < name > < / name >

    < value > < / value >

    < > 1.2.3 ErrorCode < / ErrorCode >

    < > < ErrorCode > 4.5.6 ErrorCode

    < ErrorMessage > claim rejected because the claimIdentifier already exist in the database < / ErrorMessage >

    input < ErrorMessage > claim must match a claim < / ErrorMessage >

    < ErrorDetail > identifier request already exists in the DB < / ErrorDetail >

    < ErrorDetail > < / ErrorDetail >

    < / recordedError >

    < / includedClaimProcessingResult >

    All items have a frequency of 1, with the exception of the error code (1 or more), ErrorMessage (0 or more), & the ErrorDetail (0 or more).

    Here's my query:

    Select

    r.REC_ID,

    r.NAME,

    r.VALUE,

    EC. ERR_CODE,

    Ed. ERR_DTL,

    EM. ERR_MSG

    of xml_files xf,.

    XMLTable ('/ includedClaimProcessingResult' in passing xf.filecontent)

    columns

    Path of REC_ID NUMBER (10) "ClaimRecordIdentifier."

    Path NAME VARCHAR2 (20) recordedError/name"."

    Path of ELMNT_VAL VARCHAR2 (5) ' recordedError/value. '

    IERRC xmltype path recordedError/ErrorCode"."

    ierrd ' recordedError/ErrorDetail, xmltype path

    r ierrm xmltype path "recordedError/ErrorMessage"),

    XMLTable ('ErrorCode' adoption r.ierrc

    columns

    Path of ERR_CODE VARCHAR2 (15) '.') EC,

    XMLTable ('ErrorDetail' adoption r.ierrd

    columns

    Path of ERR_DTL VARCHAR2 (100) '.') (+) ed,.

    XMLTable ('ErrorMessage' adoption r.ierrm

    columns

    Path of ERR_MSG VARCHAR2 (100) '.') (+) em;

    I try to return the item corresponding to the first occurrence of several elements in a row values, the second occurrence is in another line, etc. (the number of possible occurrences is not static):

    REC_ID NAME VALUE ERR_CODE ERR_DTL ERR_MSG

    ----------------------             --------------------      ---------               ---------------              -----------------------------------                                        -----------------------------

    1000 pharmacy claim 1.2.3 that request identifier already exists in the DB claim rejected because the claimIdentifier already exist in the database

    1000 pharmacy claim 4.5.6 incoming claim must correspond to a claim

    Thanks for any help!

    It would be much easier if the person who designed the XML thought first about the consequences of their design...

    We can do it, but it will not perform...

    One option would be to apply an XSL to transform XML into something more logical...

    The other would be to use XQUERY...

    SQL > with MY_BAD_XML like
    () 2
    3. Select XMLTYPE)
    4'
    5 1000
    6 0x1ABC2D123456789
    7
    8            R
    9

    10
    11 request for pharmacy
    12
    13            1.2.3
    14            4.5.6
    15 application rejected because claimIdentifier already exist in the database
    16 Inbound claim must correspond to a claim

    17 request identifier already exists in the DB
    18
    19
    20 ') of the double OBJECT_VALUE
    21)
    22. Select c.
    MY_BAD_XML 23,
    24 XMLTABLE)
    25 ' for $i in $XML / includedClaimProcessingResult
    26 return result {} element
    27 for $j to $pos in $ recordedError/i/ErrorCode
    28 return element row {}
    $i 29/ClaimRecordIdentifier,
    $i 30/ClaimIdentifier,
    $i 31/classifyingProcessingStatusType/statusCode,
    $i 32/recordedError/Name,
    $i 33/recordedError/value,
    $i 34/recordedError/ErrorCode [$pos],
    $i 35/recordedError/ErrorMessage [$pos],
    $i 36/recordedError/ErrorDetail [$pos]
    37                     }
    38} / row
    39             '
    40 from OBJECT_VALUE as 'XML '.
    41 columns
    42 path of the ClaimRecordIdentifier VARCHAR2 (32) "ClaimRecordIdentifier".
    43, path of the ClaimIdentifier VARCHAR2 (32) "ClaimIdentifier".
    44, path VARCHAR2 (32) statusCode 'statusCode '.
    45, path name VARCHAR2 (32) 'name '.
    46, path of VARCHAR2 value (32) 'value '.
    47, path VARCHAR2 (32) error code "error Code".
    48, path VARCHAR2 (32) ErrorMessage "ErrorMessage".
    49, path of ErrorDetail VARCHAR2 (32) "ErrorDetail.
    (50) c
    51.

    CLAIMRECORDIDENTIFIER CLAIMIDENTIFIER
    -------------------------------- --------------------------------
    STATUSCODE NAME
    -------------------------------- --------------------------------
    ERRORCODE VALUE
    -------------------------------- --------------------------------
    ERRORMESSAGE ERRORDETAIL
    -------------------------------- --------------------------------
    1000 0x1ABC2D123456789
    Pharmacy claim R
    1.2.3
    Request rejected because claimIden request identifier already exists

    CLAIMRECORDIDENTIFIER CLAIMIDENTIFIER
    -------------------------------- --------------------------------
    STATUSCODE NAME
    -------------------------------- --------------------------------
    ERRORCODE VALUE
    -------------------------------- --------------------------------
    ERRORMESSAGE ERRORDETAIL
    -------------------------------- --------------------------------
    1000 0x1ABC2D123456789
    Pharmacy claim R
    4.5.6
    Incoming claim must correspond to a claim

    SQL >

Maybe you are looking for

  • How to restore a folder and subfolders using Time Machine (TM)?

    I need to restore a folder and all its files and subfolders, with the latest at a specific date. I'm running Yosemite (10.10.5) and plan to upgrade to El Capitan, shortly. To the restored file, includes everything I have he would have seen that day. 

  • Turn on javascript

    Hello, I am using windows vista with firefox 3.6.6 I could listen to the BBC radio, but later on upgrade Firefox I can't do. Given that this log and error 'enable javascript' despite the fact that it is activate. I need play BBC with another web brow

  • Public folders in Windows 7

    Hello We have issues where a library users is using both their folder my documents, as well as the public documents folder. Is there a way to remove this access, or at least remove the public documents in the libraries? as a large amount of users beg

  • Presario S3310CL cannot windows install XP

    I have a Presario S3310CL, 2.5 GHZ, 512 MB, 120 GB.  I don't have a disc of recovery for this one, but I have a Windows XP CD.  I have nothing to record from the hard disk. Here's what happens: When I turn on the computer I press F10 Set - up is load

  • I have bougth Lightroom. Program do not work. I don't have a code. Than me?

    Hello ! 16/02/2016. , I   am -EMMANUEL REGINA JANSONE- I bought a program Lightroom! I do not understand how I run the program! How can I get a serial number or key! You give LIGHTROOM TRIAL for 30 days!Why!  I don't! How do I a licence? What I do ne