Conversion of extractValue XMLTABLE

Hello world

I recently discovered extractValue is obsolete and I am trying to convert my code XMLTABLE.

Examples, I found on this forum and other places, I think I have the right to the syntax, but it does not return all the values of the XMLTABLE call.

My version is: Oracle Database 11 g Enterprise Edition Release 11.2.0.3.0 - 64 bit

SELECT xt.po_num, xt.vendor,

extractValue (p_t.po_xml_data, ' / PurchaseOrder/PO_Num ',' xmlns = "http://tempuri.org/" ' ")

OF p_t po_table,.

XMLTable (XMLNamespaces (default 'http://tempuri.org/'), )

' / PurchaseOrder'

PASSAGE po_table.po_xml_data

COLUMNS

po_num PATH VARCHAR2 (12) "PO_Num."

provider path ACCESS of VARCHAR2 (12) "PO_Vendor") xt

where p_t.po_xml_data_id = '366000000008143';

The "extractValue" returns the number of PO for this record.  The other two columns are null.

The XML data in the po_xml_data of XMLTYPE column in this record looks like this:

"< PurchaseOrder xmlns = 'http://tempuri.org/" "xmlns: xsi ="http://www.w3.org/2001/XMLSchema-instance"> " "

"< PO_Num xmlns:ns4 ="http://tempuri.org/"ns4:IsFlagged ="false"> 123454 < / PO_Num >"

"< PO_Vendor xmlns:ns4 ="http://tempuri.org/"ns4:IsFlagged ="false"> HP < / PO_Vendor >"

< / PurchaseOrder >

I appreciate any help you can offer.

Thank you

Jack

Hi Jack,

You have the right XMLTABLE syntax.

But I do not reproduce the behavior you describe.

When I tried to run the query, I get:

ORA-00904: "PO_TABLE." "" PO_XML_DATA ": invalid identifier

Shouldn't this part: PASS po_table.po_xml_data

read this instead: p_t.po_xml_data of PASSAGE?

Once the problem is corrected, I have another error, which is, in my view, the real issue here:

SQL> create table po_table (po_xml_data_id varchar2(30), po_xml_data xmltype);

Table created.

SQL>
SQL> insert into po_table
  2  values ('366000000008143', xmltype('
  3    123454
  4    HP
  5  '));

1 row created.

SQL> commit;

Commit complete.

SQL> SELECT xt.po_num, xt.vendor,
  2         extractValue(p_t.po_xml_data, '/PurchaseOrder/PO_Num', 'xmlns="http://tempuri.org/"')
  3    FROM  po_table p_t,
  4          XMLTable(XMLNamespaces(default 'http://tempuri.org/'),
  5          '/PurchaseOrder'
  6                PASSING po_table.po_xml_data
  7                COLUMNS
  8                 po_num VARCHAR2(12) PATH 'PO_Num',
  9                 vendor VARCHAR2(12) PATH 'PO_Vendor') xt
 10  where p_t.po_xml_data_id = '366000000008143';
              PASSING po_table.po_xml_data
                      *
ERROR at line 6:
ORA-00904: "PO_TABLE"."PO_XML_DATA": invalid identifier

SQL> SELECT xt.po_num, xt.vendor,
  2         extractValue(p_t.po_xml_data, '/PurchaseOrder/PO_Num', 'xmlns="http://tempuri.org/"')
  3    FROM  po_table p_t,
  4          XMLTable(XMLNamespaces(default 'http://tempuri.org/'),
  5          '/PurchaseOrder'
  6                PASSING p_t.po_xml_data
  7                COLUMNS
  8                 po_num VARCHAR2(12) PATH 'PO_Num',
  9                 vendor VARCHAR2(12) PATH 'PO_Vendor') xt
 10  where p_t.po_xml_data_id = '366000000008143';
SELECT xt.po_num, xt.vendor,
*
ERROR at line 1:
ORA-19025: EXTRACTVALUE returns value of only one node

After removing the EXTRACTVALUE call, we can see why the error occurred.

Oracle retrieves the attribute node, as if it were an element, thus feeding two nodes to EXTRACTVALUE.

This is a bug, always present in the most recent version of today (12.1.0.2), but it occurs only when the attribute is qualified namespace.

SQL> SELECT xt.po_num, xt.vendor
  2         --, extractValue(p_t.po_xml_data, '/PurchaseOrder/PO_Num', 'xmlns="http://tempuri.org/"')
  3    FROM  po_table p_t,
  4          XMLTable(XMLNamespaces(default 'http://tempuri.org/'),
  5          '/PurchaseOrder'
  6                PASSING p_t.po_xml_data
  7                COLUMNS
  8                 po_num VARCHAR2(12) PATH 'PO_Num',
  9                 vendor VARCHAR2(12) PATH 'PO_Vendor') xt
 10  where p_t.po_xml_data_id = '366000000008143';

PO_NUM       VENDOR
------------ ------------
false123454  falseHP

Workaround: extract explicitly down to the text() node:

SQL> SELECT xt.po_num, xt.vendor
  2       --  extractValue(p_t.po_xml_data, '/PurchaseOrder/PO_Num', 'xmlns="http://tempuri.org/"')
  3    FROM  po_table p_t,
  4          XMLTable(XMLNamespaces(default 'http://tempuri.org/'),
  5          '/PurchaseOrder'
  6                PASSING p_t.po_xml_data
  7                COLUMNS
  8                 po_num VARCHAR2(12) PATH 'PO_Num/text()',
  9                 vendor VARCHAR2(12) PATH 'PO_Vendor/text()') xt
 10  where p_t.po_xml_data_id = '366000000008143';

PO_NUM       VENDOR
------------ ------------
123454       HP

Tags: Oracle Development

Similar Questions

  • 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 ;
    
  • 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

  • Values for timestamp default XMLTable causes ORA-01843: not one month valid

    When I try to provide a default value for a timestamp value in the function XMLTABLE, I am greeted with an error - ORA-01843: not one month valid -no matter how to give this default value. If there is a value in the XML or not is irrelavant to this bug occurs. It seems to be an incomplete correction of bug number 9745897 (thread).

    Select x.*

    Of

    XMLTable ('/ DOC' from xmltype ("< DOC > < DT > 2013-08-14T 15: 08:31 < /DT > < / DOC > '"))

    DT COLUMNS timestamp default sysdate) x;

    Select x.*

    Of

    XMLTable ('/ DOC' from xmltype ("< DOC > < DT > 2013-08-14T 15: 08:31 < /DT > < / DOC > '"))

    By default systimestamp timestamp COLUMNS DT) x;

    Select x.*

    Of

    XMLTable ('/ DOC' from xmltype ("< DOC > < DT > 2013-08-14T 15: 08:31 < /DT > < / DOC > '"))

    DT of COLUMNS timestamp default to_char (systimestamp, ' ' YYYY-MM-DD "T" HH24:MI:SS)) x;)

    Edit: somewhat more followed.

    It works:

    Select x.*

    Of

    XMLTable ('/ DOC' from xmltype ("< DOC > < / DOC > '"))

    Date of the dt of COLUMNS by default sysdate) x;

    It works, too, with the exception of its just the date and not the time

    Select x.*

    Of

    XMLTable ('/ DOC' from xmltype ("< DOC > < / DOC > '"))

    DT COLUMNS timestamp default sysdate) x;

    It does not work

    Select x.*

    Of

    XMLTable ('/ DOC' from xmltype ("< DOC > < / DOC > '"))

    By default systimestamp timestamp COLUMNS DT) x;

    ORA-01861: literal does not match the format string

    Hello

    First of all, let's check the manual for the DEFAULT clause:

    Function SQL/XML XMLTABLE in Oracle XML DB

    The optional parameter DEFAULT clause specifies the value to use when the PATH expression results in an empty sequence (or NULL ). His expr is an XQuery expression that is evaluated to produce the default value.

    According to the documentation, the DEFAULT clause must specify an XQuery expression.

    However, is false, the implementation only expects an expression that matches a string, the content is not interpreted.

    Bottom line is, if we specify directly a string, the expression is implicitly converted into one, and everyone knows how things can go when implicit conversions appear, especially when the dates or timestamps are involved.

    Now let's focus on the impact of the DEFAULT clause on the evaluation of the query.

    When a DEFAULT clause is specified, Oracle has rewritten projection differently and does not use the native format of XS: DateTime to convert the value:

    Select x.*

    Of

    XMLTable ('/ DOC' from xmltype ('))

    2013-08-14 T 15: 08:31
    ')

    DT of COLUMNS by default systimestamp timestamp

    ) x

    becomes:

    SELECT THE EXISTSNODE (VALUE(KOKBF$), '/ DOC/DT')

    WHEN 1 THEN LAUNCH (TO_TIMESTAMP (SYS_XQ_UPKXML2SQL (SYS_XQEXVAL (SYS_XQEXTRACT (VALUE(KOKBF$), '/ DOC/DT')), 50.1, 2)() as a timestamp)

    ELSE CAST (TO_TIMESTAMP (TO_CHAR (SYSTIMESTAMP (6)), 'SYYYY-MM-DD "T" HH24:MI:SSXFF') AS timestamp)

    END "DT".

    TABLE ("SYS". "XQSEQUENCE"(EXTRACT ("SYS"." XMLTYPE"(")

    2013-08-14 T 15: 08:31
    (((,'/ DOC'))) ' KOKBF$ '.

    See the red part: it does not use the format parameter, the conversion depends on NLS session parameters.

    When there is no DEFAULT clause, the TO_TIMESTAMP function uses an explicit format:

    Select x.*

    Of

    XMLTable ('/ DOC' from xmltype ('))

    2013-08-14 T 15: 08:31
    ')

    Dt timestamp - default systimestamp COLUMNS

    ) x

    rewritten to:

    SELECT CAST)

    TO_TIMESTAMP)

    SYS_XQ_UPKXML2SQL (SYS_XQEXVAL (SYS_XQEXTRACT (VALUE(KOKBF$), '/ DOC/DT'), 0,0,20971520, 0), 50.1, 2)

    "SYYYY-MM-DD"T"HH24:MI:SSXFF"

    )

    BY timestamp - default systimestamp

    ) "DT".

    TABLE ("SYS". "XQSEQUENCE"(EXTRACT ("SYS"." XMLTYPE"(")

    2013-08-14 T 15: 08:31
    (((,'/ DOC'))) ' KOKBF$ '.

    So yes, maybe there is a bug here.

    Edit: somewhat more followed.

    It works:

    Select x.*

    Of

    XMLTable ('/ DOC' from xmltype (""))

    Date of the dt of COLUMNS by default sysdate) x;

    Actually no, it does not work. Certainly, maybe it produces no error, but the result is incorrect.

    As explained, the conversion is based on the NLS (NLS_DATE_FORMAT in this case) session:

    SQL > show nls_date_format settings

    VALUE OF TYPE NAME

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

    string of NLS_DATE_FORMAT JJ/MM/RR

    SQL >

    SQL > select sysdate to double;

    SYSDATE

    --------

    16/08/13

    SQL > select x.*

    2 from

    3 xmltable ('/ DOC' passing xmltype (""))

    4 COLUMNS dt date default sysdate) x;

    DT

    --------

    13/08/16

    Oracle first converts SYSDATE to a string using current NLS_DATE_FORMAT, having for result Aug 16, 13 '

    Then this string is converted to a DATE as XS: date is 'YYYY-MM-DD' leading 13/08/16 (13 August, 0016) which is incorrect.

    The obvious solution to this problem is to control how Oracle converts implicitly string to timestamp format:

    SQL > alter session set NLS_TIMESTAMP_FORMAT = "YYYY-MM-DD"T"HH24:MI:SS."

    Modified session.

    SQL > select x.*

    2 from

    3 xmltable ('/ DOC' from xmltype ('))

    2013-08-14 T 15: 08:31
    ')

    4 dt of systimestamp default timestamp COLUMNS

    (5) x;

    DT

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

    2013-08-14 T 15: 08:31

    SQL > select x.*

    2 from

    3 xmltable ('/ DOC' passing xmltype (""))

    4 dt of COLUMNS by default systimestamp timestamp) x;

    By default systimestamp timestamp COLUMNS DT) x

    *

    ERROR on line 4:

    ORA-01861: literal does not match the format string

    SQL > select x.*

    2 from

    3 xmltable ('/ DOC' passing xmltype (""))

    Cast of default timestamp COLUMNS dt (systimestamp timestamp) 4) x;

    DT

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

    2013 08-16 T 12: 32:58

  • 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.

  • 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
    
  • extraction of XML with xmltable

    Because I recently received a comment here on OTN that extract/extractvalue should no more be used to extract the XML I was playing with xmltable.
    However, I use a little problem.

    I am trying to extract a very simple piece of xml in this way:
    SELECT d.*
      FROM (SELECT xmltype ('<ArrayOfstring>
                               <string>415391</string>
                               <string>415392</string>
                          </ArrayOfstring>
    ')
                      x
              FROM DUAL),
           XMLTABLE ('$d/ArrayOfstring'
                     PASSING x AS "d"
                     COLUMNS string VARCHAR2 (100) PATH 'string') d;
    and I get this error: XPTY0004 - dynamic XQuery type mismatch: expected - singleton sequence got several sequence element

    I do not understand what goes wrong, since the same code work with a more complex pieve of XML:
    SELECT d.*
      FROM (SELECT xmltype ('<ArrayOfProperties>
                            <Properties>
                                <Id>98247</Id>
                                <code>001</code>
                                <name>4 Megapixel</name>
                            </Properties>
                            <Properties>
                                <Id>98248</Id>
                                <code>001</code>
                                <name>5 Megapixel</name>
                            </Properties>
                        </ArrayOfProperties>') x FROM DUAL),
           XMLTABLE (
              '$d/ArrayOfProperties/Properties'
              PASSING x AS "d"
              COLUMNS Id VARCHAR2 (100) PATH 'Id',
                      Naam VARCHAR2 (4000) PATH 'name',
                      code VARCHAR2 (100) PATH 'code') d                 
    Published by: Erik_NL on July 20, 2012 06:11

    You have two elements of the chain at the same level.

    So, something like:

    SQL> SELECT d.*
      2    FROM (SELECT xmltype ('
      3                             415391
      4                             415392
      5                        ')
      6                    x
      7            FROM DUAL),
      8         XMLTABLE ('$d/ArrayOfstring/string'
      9                   PASSING x AS "d"
     10                   COLUMNS string VARCHAR2 (100) PATH '/string') d;
    
    STRING
    ------------------------------------------------------------------------------
    415391
    415392
    
    SQL> 
    
  • XML - ORA-19025: EXTRACTVALUE returns the value of a single node

    Hello

    I'm new to XML DB. Can someone help me with the below XML

    I use the following XML... (I pasted a part only of it coz I need data only up to this article)

    XML
    --------------------

    <? XML version = "1.0" encoding = "UTF-8"? > < SOAP - ENV:Envelope xmlns:SOAP - ENV = "http://schemas.xmlsoap.org/soap/envelope/" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-."
    example"container ="http://www.w3.org/2001/XMLSchema"> < SOAP - ENV:Body >
    < ns:PicklistWS_GetPicklistValues_Output xmlns:ns = "urn: crmondemand/ws/list dropdown /" >
    < ListOfParentPicklistValue xmlns = "urn: / xml/crmondemand/list of choices" >
    < ParentPicklistValue >
    < language > ENU < / language >
    < ParentFieldName > plProduct_Team < / ParentFieldName >
    < ParentDisplayValue > Marketing On Demand < / ParentDisplayValue >
    < ParentCode > Marketing On Demand < / ParentCode >
    < Disabled > N < / disabled >
    < ListOfPicklistValue >
    < PicklistValue >
    Escalation of OCP/SME < code > < code >
    Escalation of OCP/SME < DisplayValue > < / DisplayValue >
    < Disabled > N < / disabled >
    < / PicklistValue >
    < PicklistValue >
    Ask fusion < code > < code >
    Merge request < DisplayValue > < / DisplayValue >
    < Disabled > N < / disabled >
    < / PicklistValue >



    Code
    ---------




    SELECT distinct
    EXTRACTVALUE (value (SR), ' / ParentPicklistValue/ListOfPicklistValue/PicklistValue/Code ','xmlns = "urn: / crmondemand/xml/list of choices"') AS display.
    Return EXTRACTVALUE (value (SR),'/ ParentPicklistValue/ListOfPicklistValue/PicklistValue/DisplayValue ',' xmlns = "urn: / crmondemand/XML/picklist"'),.
    EXTRACTVALUE (value (SR), '/ ParentPicklistValue/ParentDisplayValue','xmlns = "urn: / crmondemand/XML/picklist"') AS parent_display,
    EXTRACTVALUE (value (SR), '/ ParentPicklistValue/ParentCode','xmlns = "urn: / crmondemand/XML/picklist"') AS parent_return
    TABLE (XMLSEQUENCE ((EXCERPT)
    WEB_SERVICE (' <? xml version = "1.0" encoding = "UTF - 8" standalone = "no"? > < envelope soap: xmlns:soap = "http://schemas.xmlsoap.org/soap/envelope/")
    xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" container = "http://www.w3.org/2001/XMLSchema" >
    < soap: Body >
    < PicklistWS_GetPicklistValues_Input xmlns = "urn: crmondemand/ws/list dropdown /" >
    Type < FieldName > < / FieldName >
    Service request < RecordType > < / RecordType >
    < / PicklistWS_GetPicklistValues_Input >
    < / soap: Body >
    "< / envelope soap: >.
    (' document / urn: crmondemand/ws/list dropdown /: ' GetPicklistValues, Id_de_la_session).
    "/: soap envelope / soap: Body / * / * / * ',' xmlns:soap ="(http://schemas.xmlsoap.org/soap/envelope/'))) SR "


    ERROR
    ---------

    ORA-19025: EXTRACTVALUE returns the value of a single node


    UNDERSTANDING
    ---------------------------

    As my Xpath only points until the node - ParentPicklistValue and not the child nodes under it. That's why, when I try to interview the child nodes - / ParentPicklistValue/ListOfPicklistValue/PicklistValue/Code, I get the error mentioned above.

    REQUIREMENT
    -----------------------

    Can someone help me to receive the values of the mother and child values based on xml and query above.

    Hello

    It's a classic ;)

    You need a second XMLSequence who shreds the collection of PicklistValue in relational lines:

    select extractvalue(value(sr2), '/PicklistValue/Code', 'xmlns="urn:/crmondemand/xml/picklist"') AS Display
         , extractvalue(value(sr2), '/PicklistValue/DisplayValue', 'xmlns="urn:/crmondemand/xml/picklist"') AS Return
         , extractvalue(value(sr1), '/ParentPicklistValue/ParentDisplayValue', 'xmlns="urn:/crmondemand/xml/picklist"') AS parent_display
         , extractvalue(value(sr1), '/ParentPicklistValue/ParentCode', 'xmlns="urn:/crmondemand/xml/picklist"') AS parent_return
    from table(
           xmlsequence(
             extract( WEB_SERVICE( ... )
                    , '/soap:Envelope/soap:Body/ns:PicklistWS_GetPicklistValues_Output/ListOfParentPicklistValue/ParentPicklistValue'
                    , 'xmlns="urn:/crmondemand/xml/picklist"
                       xmlns:ns="urn:crmondemand/ws/picklist/"
                       xmlns:soap="http://schemas.xmlsoap.org/soap/envelope/"' )
           )
         ) sr1
       , table(
           xmlsequence(
             extract( value(sr1)
                    , '/ParentPicklistValue/ListOfPicklistValue/PicklistValue'
                    , 'xmlns="urn:/crmondemand/xml/picklist"' )
           )
         ) sr2
    ;
    

    What is your version of the database BTW?
    10.2 and upward, you can use the XMLTable.

  • ExtractValue

    BANNER
    Oracle Database 11g Enterprise Edition Release 11.2.0.2.0 - 64bit Production
    PL/SQL Release 11.2.0.2.0 - Production
    CORE     11.2.0.2.0     Production
    TNS for HPUX: Version 11.2.0.2.0 - Production
    NLSRTL Version 11.2.0.2.0 - Production
    /* Formatted on 4/5/2012 5:18:38 PM (QP5 v5.185.11230.41888) */
    DROP TABLE mytab;
    
    CREATE TABLE mytab
    (
       job_request_id         INTEGER,
       job_parameter_id_xml   XMLTYPE
    );
    
    SET DEFINE OFF;
    
    INSERT INTO mytab (JOB_REQUEST_ID, JOB_PARAMETER_ID_XML)
         VALUES (
                   858554,
                   XMLTYPE (
                      '<PivotSet><item><column name = "JOB_PARAMETER_ID">1000</column><column name = "VALUE_TX">208844</column></item><item><column name = "JOB_PARAMETER_ID">1001</column><column name = "VALUE_TX">165972</column></item><item><column name = "JOB_PARAMETER_ID">1007</column><column name = "VALUE_TX">3</column></item><item><column name = "JOB_PARAMETER_ID">1008</column><column name = "VALUE_TX">1580</column></item></PivotSet>'));
    
    INSERT INTO mytab (JOB_REQUEST_ID, JOB_PARAMETER_ID_XML)
         VALUES (
                   858555,
                   XMLTYPE (
                      '<PivotSet><item><column name = "JOB_PARAMETER_ID">1000</column><column name = "VALUE_TX">261015</column></item><item><column name = "JOB_PARAMETER_ID">1001</column><column name = "VALUE_TX">189185</column></item><item><column name = "JOB_PARAMETER_ID">1007</column><column name = "VALUE_TX">3</column></item><item><column name = "JOB_PARAMETER_ID">1008</column><column name = "VALUE_TX">25</column></item></PivotSet>'));
    
    COMMIT;
    expected results
     job_request_id    1000        1001           1007       1008
     858554             208844     165972        3            1580
     85855               261015     189185        3            25
    not very strong with the xml stuff, I read the documentation on certificate of value, but I couldn't make it work. any help is appreciated thank you.

    Hello

    A few comments:

    (1) forget the extractvalue() function, it is discouraged in your version. Oracle recommends using the XQuery XMLQuery() and XMLTable() functions now.

    (2) I see you try to work on the content provided by the operator PIVOT XML, but as always, unless you know the number of columns expected in advanceyou can have any output in relational format by using a simple SELECT statement. You can do this with ODCI but I don't think you want to go this way.

    So basically what follows, but it clearly defeated the purpose of using a PivotChart in the first place:

    SQL> select t.job_request_id, x.*
      2  from mytab t
      3     , xmltable(
      4         '/PivotSet'
      5         passing t.job_parameter_id_xml
      6         columns "1000" number path 'item[column[1]="1000"]/column[2]'
      7               , "1001" number path 'item[column[1]="1001"]/column[2]'
      8               , "1007" number path 'item[column[1]="1007"]/column[2]'
      9               , "1008" number path 'item[column[1]="1008"]/column[2]'
     10       ) x
     11  ;
    
                             JOB_REQUEST_ID       1000       1001       1007       1008
    --------------------------------------- ---------- ---------- ---------- ----------
                                     858554     208844     165972          3       1580
                                     858555     261015     189185          3         25
     
    

    If you are looking for a text output only, it's another story like this boils down to the aggregation of the chain, but once again this could be done more simply without resorting to format XML PIVOT.
    A quick attempt using an tab separator:

    SQL> select 'JOB_REQUEST_ID' || chr(9) ||
      2         xmlcast(
      3           xmlquery('let $sep := codepoints-to-string(9)
      4                     return string-join(/PivotSet/item/column[@name="JOB_PARAMETER_ID"], $sep)'
      5                    passing JOB_PARAMETER_ID_XML
      6                    returning content)
      7           as varchar2(4000)
      8         ) as report
      9  from mytab
     10  where rownum = 1
     11  union all
     12  select to_char(job_request_id) || chr(9) ||
     13         xmlcast(
     14           xmlquery('let $sep := codepoints-to-string(9)
     15                     return string-join(/PivotSet/item/column[@name="VALUE_TX"], $sep)'
     16                    passing JOB_PARAMETER_ID_XML
     17                    returning content)
     18           as varchar2(4000)
     19         )
     20  from mytab
     21  ;
    
    REPORT
    --------------------------------------------------------------------------------
    JOB_REQUEST_ID     1000     1001     1007     1008
    858554     208844     165972     3     1580
    858555     261015     189185     3     25
     
    
  • XmlType extractValue with namespace throw exception "invalid token".

    Hello. I have XML stored as XMLTYPE and with content, such as:

    + < notificationEF > +.
    + < oos:id > 2812301 < / oos:id > +.

    When I try to run

    extractValue (XML_CLOB, ' notificationEF / oos:id ')

    I catch exception "LPX-00601: token not valid in:" notificationEF / oos:id' "."

    What's wrong? And how do I fix it?

    Thank you.

    Here's one way:

    SQL> var xmldoc varchar2(4000)
    SQL>
    SQL> begin
      2   :xmldoc :=
      3  '
      4  
      7   
      8    4711561
      9    4711561
     10   
     11  ';
     12  end;
     13  /
    
    PL/SQL procedure successfully completed
    
    SQL> SELECT x.id
      2  FROM XMLTable(
      3         XMLNamespaces(
      4           default 'http://example.ru/oos/export/1'
      5         , 'http://example.ru/oos/types/1' as "oos"
      6         )
      7       , '/export/contract/oos:id'
      8         passing xmltype(:xmldoc)
      9         columns id number path '.'
     10       ) x
     11  ;
    
            ID
    ----------
       4711561
       4711561
     
    
  • 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.

  • EXTRACTVALUE returns more than one row error

    Hi gurus

    I have XML file, now I would like to write an SQL to convert tabular. Whne I try to use

    EXTRACTVALUE
    (XML_MESSAGE,
    ' / ATMWithDrawTrans/Trans/Tran/TranDate.

    I'm ExtractValue returns multiple rows. Could you please help me find a query that retrieves these sub table form.

    < ATMWithDrawTrans >
    < Trans >
    < Tran >
    < TranDate > 2001 - 09 - 10 < / TranDate >
    < amount > 105 < / amount >
    < / Tran >
    < Tran >
    < TranDate > 2002 - 03 - 10 < / TranDate >
    < amount > 105 < / amount >
    < / Tran >
    < Tran >
    < TranDate > 2002 - 09 - 10 < / TranDate >
    < amount > 104 < / amount >
    < / Tran >
    < Tran >
    < TranDate > 2003 - 03 - 10 < / TranDate >
    < amount > 104 < / amount >
    < / Tran >
    < Tran >
    < TranDate > 2003 - 09 - 10 < / TranDate >
    < amount > 103 < / amount >
    < / Tran >
    < / Trans >
    < / ATMWithDrawTrans >

    TIA

    Published by: 870046 on July 25, 2011 08:50

    XMLTable will do what you want.

    For example, assuming XML_MESSAGE is a database of XMLType column:

    select x.*
    from your_table t
       , xmltable('/ATMWithDrawTrans/Trans/Tran'
           passing t.xml_message
           columns tran_date date   path 'TranDate'
                 , amount    number path 'amount'
         ) x
    ;
    

    If your version does not support, see XMLSequence in the documentation.

  • Insert stmt fail with ORA 1400 to use extractvalue in tab xmltype.

    insert into USER_CMNT select extractvalue (xmlfile1,
    ("/ ONLINE/USER_CMNT_ID '),
    ExtractValue (xmlfile1,
    ("/ LINE/OPERATOR_ID").
    ExtractValue (xmlfile1,
    ("/ ONLINE/CMNT_TEXT '),
    ExtractValue (xmlfile1,
    ("/ ONLINE/CMNT_DTMS")
    of gt_xmltype_tab gt,.
    TABLE (XMLSequence (extract (gt.xmlfile1, ' / LINES/LINE '))) x

    I'm running above stmt insert in the following table...

    user_cmnt / / DESC
    Name Null? Type
    USER_CMNT_ID NOT NULL NUMBER
    OPERATOR_ID VARCHAR2 (3)
    CMNT_TEXT NOT NULL VARCHAR2 (120)
    CMNT_DTMS NOT NULL DATE


    GT is a global temporary table that contains the following data in the xmltype column.

    <? XML version = "1.0"? >
    rowset <>
    < ROW >
    < USER_CMNT_ID > 1 < / USER_CMNT_ID >
    < OPERATOR_ID > 4 < / OPERATOR_ID >
    < CMNT_TEXT > Noémie test < / CMNT_TEXT >
    < CMNT_DTMS > 5 May 11 < / CMNT_DTMS >
    < / ROW >
    < ROW >
    < USER_CMNT_ID > 2 < / USER_CMNT_ID >
    < OPERATOR_ID > 4 < / OPERATOR_ID >
    < CMNT_TEXT > Noémie test < / CMNT_TEXT >
    < CMNT_DTMS > 5 May 11 < / CMNT_DTMS >
    < / ROW >
    < ROW >
    < USER_CMNT_ID > 3 < / USER_CMNT_ID >
    < OPERATOR_ID > 4 < / OPERATOR_ID >
    < CMNT_TEXT > Noémie test < / CMNT_TEXT >
    < CMNT_DTMS > 5 May 11 < / CMNT_DTMS >
    < / ROW >
    < ROW >
    < USER_CMNT_ID > 4 < / USER_CMNT_ID >
    < OPERATOR_ID > 4 < / OPERATOR_ID >
    < CMNT_TEXT > Noémie test < / CMNT_TEXT >
    < CMNT_DTMS > 5 May 11 < / CMNT_DTMS >
    < / ROW >
    < ROW >
    < USER_CMNT_ID > 5 < / USER_CMNT_ID >
    < OPERATOR_ID > 4 < / OPERATOR_ID >
    < CMNT_TEXT > Noémie test < / CMNT_TEXT >
    < CMNT_DTMS > 5 May 11 < / CMNT_DTMS >
    < / ROW >
    < / LINES >

    I get the following error...

    ERROR on line 1:
    ORA-01400: cannot insert NULL into (USER_CMNT. USER_CMNT_ID)


    When I just run the select query to see the data I don't see no user_cmnt_id with a NULL value.


    Please notify.

    Hello

    You must apply the function extractValue on the XML fragment extracted with XMLSequence, not on the original document:

    SELECT extractvalue (x.column_value,'/ROW/USER_CMNT_ID'),
           extractvalue (x.column_value,'/ROW/OPERATOR_ID'),
           extractvalue (x.column_value,'/ROW/CMNT_TEXT'),
           extractvalue (x.column_value,'/ROW/CMNT_DTMS')
    FROM gt_xmltype_tab gt,
         TABLE(
           XMLSequence(
             extract(gt.xmlfile1, '/ROWSET/ROW')
           )
         ) x
    ;
    

    If you're on 10.2 or upward, prefer XMLTable:

    SELECT x.user_cmnt_id
         , x.operator_id
         , x.cmnt_text
         , to_date(x.cmnt_dtms,'DD-MON-RR','nls_date_language=english') as cmnt_dtms
    FROM gt_xmltype_tab gt,
         XMLTable(
          '/ROWSET/ROW'
          passing gt.xmlfile1
          columns user_cmnt_id number        path 'USER_CMNT_ID'
                , operator_id  varchar2(3)   path 'OPERATOR_ID'
                , cmnt_text    varchar2(120) path 'CMNT_TEXT'
                , cmnt_dtms    varchar2(30)  path 'CMNT_DTMS'
         ) x
    ;
    

    Published by: odie_63 on May 5, 2011 22:41

  • ExtractValue element node by using a variable

    Hello

    I have the following select statement, and it works fine.
    SELECT extractvalue (ISBN_PAYLOAD, ' / ISBNdb/BookList/BookData/Subjects/Subject [1]') in Topic1
    OF LIB_ISBN_T
    WHERE LIB_ISBN_T_PK = 1;

    It returns the first topic.

    I would like crazy across all subjects, replacing the '1' by a numeric variable. I tried the following, and I receive blanks.

    SELECT Topic1 extractvalue (ISBN_PAYLOAD, '/ ISBNdb/BookList/BookData/Subjects/Subject [(Current_Count)]')
    OF LIB_ISBN_T
    WHERE LIB_ISBN_T_PK = 1;

    In a Select statement / Extractvalue statement, how can I replace the value inside the brackets with a variable?

    Thank you very much

    Hello

    You don't need to get a counter for it.
    Here are two solutions depending on your version of the database, both based in break the XML in relational rows and columns:

    Pre-10 gr 2

    SELECT extractValue(x.column_value, '/Subject')
    INTO v_subject
    FROM lib_isbn_t t,
         TABLE(
           XMLSequence(
             Extract(
               t.isbn_payload,
               '/ISBNdb/BookList/BookData/Subjects/Subject'
             )
           )
         ) x
    WHERE t.lib_isbn_t_pk = 1
    ;
    

    10 gr 2 and +.

    SELECT x.subject
    INTO v_subject
    FROM lib_isbn_t t,
         XMLTable(
           '/ISBNdb/BookList/BookData/Subjects/Subject'
           passing t.isbn_payload
           columns subject varchar2(30) path '.'
         ) x
    WHERE t.lib_isbn_t_pk = 1
    ;
    
  • 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;
    

Maybe you are looking for

  • Air2 iPad, iOS 9.3.1 Safari no longer intermittently.

    When you use Safari on my iPad Air2, iOS 9.3.1 pages hang.  By this, I mean that it does not have to press ENTER.  It usually lasts for 5-10 seconds and then all is well again for a while and then, it happens over and over again... I don't have any o

  • 15 - f305dx: I need a discount to zero-92122312 administrative

    Can someone help me with an administrative PW reset? I have a 92122312 deactivation code. Thank you.

  • Inaccessible boot device error. New motherboard.

    De : Meigs I'm changing my motherboard that supports the quad core processor. However, I get an inaccessible boot device error when I try to boot with the new motherboard. I tried to boot from the installation dvd and repair, but it cannot solve the

  • Dialog box Windows Defender log in

    Dialog box Windows Defender log in: initialization failed: 0 x 80070006. The handle is invisible. What is this and how can I change? (I run ESET on Vista)

  • Lost my internet connection, even when wired

    My laptop was working fine then one day just stopped connecting to the internet.  I have a computer dell laptop (Inspiron 1525) with vista.  I ran each test there is.  He says that I have "local".  I try cable and wireless tried to obtain a new ip ad