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
 

Tags: Database

Similar Questions

  • 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
    
  • 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
    
  • Helps the namespace definition in extractvalue()

    Hello

    I use PL/SQL on Oracle Enterprise Edition 11.2.0.3.0 to call a Web service.

    I have an answer in a variable of type xmltype.

    I am trying to extract the md5sum value, but I can't specify the correct namespace for the extractvalue function.

    The XML response is
    < GetFileDetailsResponse xmlns = "http://10.1.0.1" >
    < GetFileDetailsResult >
    < FileDetails xmlns = "" >
    908655930beaa7ea3bca7a98adabfcf4 < md5sum > < / md5sum >
    < FileSize > 50929664 < / size >
    < FileLastModified > 2011 - 05 - 03T 12: 33:16 + 01:00 < / FileLastModified >
    < / FileDetails >
    < / GetFileDetailsResult >
    < / GetFileDetailsResponse >

    Simplfying this down I built the following select statement

    Select extractvalue (xmltype.createxml ("< GetFileDetailsResponse xmlns ="http://10.1.0.1">))
    < GetFileDetailsResult >
    < FileDetails xmlns = "" >
    908655930beaa7ea3bca7a98adabfcf4 < md5sum > < / md5sum >
    < FileSize > 50929664 < / size >
    < FileLastModified > 2011 - 05 - 03T 12: 33:16 + 01:00 < / FileLastModified >
    < / FileDetails >
    < / GetFileDetailsResult >
    (< / GetFileDetailsResponse > '), ' / GetFileDetailsResponse/GetFileDetailsResult/FileDetails/md5sum ','xmlns = "http://10.1.0.1" xmlns = "" ') md5 twice; "

    This property returns null

    However, if I remove two references in the XML namespace.

    Select extractvalue (xmltype.createxml ("< GetFileDetailsResponse >
    < GetFileDetailsResult >
    < FileDetails >
    908655930beaa7ea3bca7a98adabfcf4 < md5sum > < / md5sum >
    < FileSize > 50929664 < / size >
    < FileLastModified > 2011 - 05 - 03T 12: 33:16 + 01:00 < / FileLastModified >
    < / FileDetails >
    < / GetFileDetailsResult >
    ((< / GetFileDetailsResponse > '), ' / GetFileDetailsResponse/GetFileDetailsResult/FileDetails/md5sum ') double md5;

    908655930beaa7ea3bca7a98adabfcf4 - get the answer I want. Looks like I'm specifying the wrong namespace in the statement of extractvalue.

    Can someone suggest the statement correct extractvalue I should use. I looked at probably this too long - I'm misses what is obvious.

    Thank you for taking the time to read this,

    See you soon,.

    Derek

    Hello

    Because the XPath of done refers to elements in a namespace and elements in no namespace, you must declare a prefix for the default namespace:

    SQL> select extractvalue(
      2    xmltype.createxml('
      3  
      4  
      5  908655930beaa7ea3bca7a98adabfcf4
      6  50929664
      7  2011-05-03T12:33:16+01:00
      8  
      9  
     10  ')
     11  , '/ns0:GetFileDetailsResponse/ns0:GetFileDetailsResult/FileDetails/md5sum'
     12  , 'xmlns:ns0="http://10.1.0.1"'
     13  ) md5
     14  from dual;
    
    MD5
    --------------------------------------------------------------------------------
    908655930beaa7ea3bca7a98adabfcf4
     
    

    But... extractValue is frowned upon in your version.
    You should now use XQuery functions:

    SQL> DECLARE
      2
      3    response xmltype := xmltype(
      4    '
      5  
      6  
      7  908655930beaa7ea3bca7a98adabfcf4
      8  50929664
      9  2011-05-03T12:33:16+01:00
     10  
     11  
     12  ');
     13
     14    result  varchar2(80);
     15
     16  BEGIN
     17
     18    select /*+ no_xml_query_rewrite */
     19           xmlcast(
     20             xmlquery(
     21             'declare namespace ns0 = "http://10.1.0.1"; (: :)
     22             /ns0:GetFileDetailsResponse/ns0:GetFileDetailsResult/FileDetails/md5sum'
     23             passing response
     24             returning content
     25             )
     26            as varchar2(80)
     27          )
     28    into result
     29    from dual
     30    ;
     31
     32    dbms_output.put_line(result);
     33
     34  END;
     35  /
    
    908655930beaa7ea3bca7a98adabfcf4
    
    PL/SQL procedure successfully completed
     
    
  • XMLCast, XMLQuery vs extractValue

    Hello fellows, newbie question - I am unable to find a working example to extract the values using the XMLQuery/XMLCast to replace the obsolete extractValue

    Here is an XMLTYPE containing
    < CalculateFITResponse xmlns = "http://tempuri.org/" >
    < CalculateFITResult xmlns: a = "http://schemas.datacontract.org/2004/07/ValueNavigatorService.Classes" xmlns:i = "http://www.
    w3.org/2001/XMLSchema-instance">
    < a: VnSegments / >
    < a: declineRate > 0 < / a: declineRate >
    < a: entityId > 128041676 < / a: entityId >
    < a: eur > 0 < / has: eur >
    < a: historyVolume > 60000 < / a: historyVolume >
    < a: results > FitSuccessful < / a: results >
    < a: segmentData xmlns: b = "http://schemas.datacontract.org/2004/07/Eni.ValueNavigator.DeclineFitting" / >
    < a: segmentDataList xmlns: b = "http://schemas.datacontract.org/2004/07/Eni.ValueNavigator.DeclineFitting" / >
    < a: segmentVolume > 0 < / a: segmentVolume >
    < / CalculateFITResult >
    < / CalculateFITResponse >

    This function-
    Get_EUR_V_Results (CalculateFIT_OutputMessage IN XMLTYPE) RETURN of the FUNCTION to CREATE or REPLACE VARCHAR2
    IS
    V_Result VARCHAR2 (4000): = NULL;
    l_ns_1 VARCHAR2 (4000): = ' xmlns: a = "http://schemas.datacontract.org/2004/07/ValueNavigatorService.Classes" ';
    l_ns_2 VARCHAR2 (4000): = 'xmlns:i = "http://www.w3.org/2001/XMLSchema-instance" ';
    l_ns_3 VARCHAR2 (4000): = 'xmlns = "http://tempuri.org/" ';
    l_ns VARCHAR2 (4000): = l_ns_1 | l_ns_2 | l_ns_3;
    l_xpath VARCHAR2 (4000): = ' / / CalculateFITResponse / / CalculateFITResult/a:';
    BEGIN
    SELECT extractValue (CalculateFIT_OutputMessage, l_xpath |) ("results, l_ns) IN V_Result of double;
    RETURN V_Result;
    END;
    /

    Returns FitSuccessful

    (successfully I might add)

    How to rewrite the function by using the XMLQuery and XMLCast?

    (Yes, I RTFM with no progress)

    Thanks in advance,

    HKT

    Hello

    (Yes, I RTFM with no progress)

    It's hard to believe...
    I found this one in less than a minute in the documentation:
    http://docs.Oracle.com/CD/E11882_01/AppDev.112/e23094/xdb_xquery.htm#BABIDFEC

    And the forum is full of examples too, just use has research with XMLCast + XMLQuery, namespace keywords.

    CREATE OR REPLACE FUNCTION get_EUR_V_Results (CalculateFIT_OutputMessage IN XMLTYPE) RETURN VARCHAR2
    IS
      V_Result VARCHAR2(4000);
    BEGIN
      SELECT XMLCast(
               XMLQuery(
               'declare default element namespace "http://tempuri.org/"; (: :)
                declare namespace a = "http://schemas.datacontract.org/2004/07/ValueNavigatorService.Classes"; (: :)
                /CalculateFITResponse/CalculateFITResult/a:results'
                passing CalculateFIT_OutputMessage
                returning content
               )
               as varchar2(4000)
             )
      INTO V_Result
      FROM dual;
    
      RETURN V_Result;
    END;
    /
    
    SQL> select get_EUR_V_Results(xmltype('
      2  
      4  
      5  0
      6  128041676
      7  0
      8  60000
      9  FitSuccessful
     10  
     11  
     12  0
     13  
     14  '))
     15  from dual;
    
    GET_EUR_V_RESULTS(XMLTYPE('
    
  • 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.

  • 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
     
    
  • extractValue XML question

    Hi all

    How to find the value of sf:Id in the next SOAP?
    When I want to find the value of the node < done > it works fine.

    I'm not able to find the value of the node < sf:Id >

    Can someone help

    Thanks in advance

    Hugo Perfors

    declare
    cl_response CLOB: = ' < soapenv:Envelope xmlns:soapenv = xmlns = ""http://schemas.xmlsoap.org/soap/envelope/"urn:enterprise.soap.sforce.com" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" xmlns:sf = "urn:sobject.enterprise.soap.sforce.com" > "
    < soapenv:Body >
    < queryResponse >
    < result >
    true <>< / fact >
    < queryLocator xsi: Nil = "true" / >
    < record xsi: type = "sf:PricebookEntry" >
    < sf:Id > 01uR0000003QxggIAC < / sf:Id >
    < / documents >
    < size > 1 < / size >
    < / result >
    < / queryResponse >
    < / soapenv:Body >
    < / soapenv:Envelope > ';
    gv_node varchar2 (100);
    gv_xmlns varchar2 (100);
    lv_id varchar2 (200);
    BEGIN
    "gv_xmlns: ="xmlns ="urn:enterprise.soap.sforce.com" ';
    gv_node: = ' / / queryResponse/result ";
    Select extractValue (value (t),'/ * / fact ', gv_xmlns) id
    in lv_id
    table (xmlsequence (excerpt (xmltype.createxml (cl_response), gv_node, gv_xmlns))) t;
    dbms_output.put_line (lv_id);
    Select extractValue (value (t),'/ * / documents / sf:id "," xmlns:sf = "urn:sobject.enterprise.soap.sforce.com" xmlns = "urn:enterprise.soap.sforce.com" xmlns: xsi = "http://www.w3.org/2001/XMLSchema-instance" ' ") id
    in lv_id
    table (xmlsequence (excerpt (xmltype.createxml (cl_response), gv_node, gv_xmlns))) t;
    dbms_output.put_line (lv_id);

    END;

    Hello

    I'm not able to find the value of the node

    Probably because you try with sf:id instead of sf:Id ;)

    Select extractValue (value (t),'/ * / sf:id ',' xmlns:sf = "urn:sobject.enterprise.soap.sforce.com" xmlns ="urn:enterprise.soap.sforce.com")

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

  • Analysis using the extractvalue XML method

    Hello
    In the XML message I want to extract values in the brochure below. That is to say john and peter

    Select EXTRACTvalue (xmltype ("<?")) XML version = "1.0" encoding ="utf - 8"? >
    < startempdetail >
    < empDetails >
    < empDetail >
    John < name > < / name >
    < / empDetail >
    < empDetail >
    Peter < name > < / name >
    < / empDetail >
    < / empDetails >
    ((< / startempdetail > '), ' / startempdetail/empDetails/empDetail/name ")
    Double;

    its not work if only john. Can someone help me solve this problem?

    Thank you!

    ExtractValue returnin only acronym row.

    Try this please

    SELECT
    extractvalue
    (EXTRACT(xmltype('
    
    
    
    john
    
    
    peter
    
    
    '), '/startempdetail/empDetails/empDetail/name'),'/name[position()='||level||']')
    from dual connect by level<=2;
    
  • 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

  • extract returns, extractvalue returns NULL

    I'm in ORACLE 10 g 10.2.0.4.0 there is a PROBLEM (NUMBER of PROBLEMID, XML_COLUMN XMLTYPE) table...

    SELECT PROBLEMID,
    EXTRACT (xml_column, ' / problem/varDefinitions/varDefinition [position () = 1]') end.
    EXTRACTVALUE (j.xml_column, ' / problem/varDefinitions/varDefinition [position () = 1] "") extrval
    PROBLEM;

    Returns:
    PROBLEMID extreme extrval


    377 < var varDefinition = "a" minValue = "8.00" unitsName = "{\rm m/s ^ 2}" maxValue = "12.0" valueStep = "1.00" format = "{3}" / > "

    Hello

    extractValue returns a scalar value (usually a text or attribute node) of a given node, not an instance of XMLType.

    So in your example, varDefinition is an empty element, extractValue gives a NULL value.

    Here is the link to the documentation:
    http://download.Oracle.com/docs/CD/B19306_01/server.102/b14200/functions052.htm#SQLRF06173

  • 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
    ;
    
  • Problem with table with XMLTYPE column extractvalue.

    I don't know there is a simple answer, but I have problems
    extract data from a column of xmltype type.
    I have two tables
    descr dab_xml
    Name
    -----------------------------------------------------
    XMLTYPE TABLE
    descr dab_test
    Name
    -----------------------------------------------------
    A NUMBER
    NUMBER OF AB
    CLOB DATA
    DATA2 VARCHAR2 (1600)
    MYXML XMLTYPE

    I inserted the Oracle XML purchaseOrder.xml example in the two dab_xml
    and the myxml in dab_test column.

    When I run the following:

    SELECT extractvalue (OBJECT_VALUE, ' / PurchaseOrder/reference "")
    OF dab_xml;

    SBELL-2002100912333601PDT returned

    When I run the present:

    SELECT extractvalue (OBJECT_VALUE, ' / PurchaseOrder/reference "")
    FROM (select dab_test myxml);

    ERROR on line 1:
    ORA-00904: "OBJECT_VALUE": invalid identifier

    Why are the two different?

    Any help will be appreciated.

    Kind regards

    David

    In short, you want to

    SELECT extractvalue(myxml, '/PurchaseOrder/Reference')
    FROM dab_test;
    

    This difference is that for dab_xml, it has no columns defined for the table, so you are [OBJECT_VALUE | http://download.oracle.com/docs/cd/B28359_01/server.111/b28286/pseudocolumns006.htm#sthref830] as an alias for a column does not exist.

    With dab_test, you have a column that contains the XML, you must use this column instead of OBJECT_VALUE name.

  • DICOM metadata - extractvalue returns the value of a single node

    Hello

    I have difficulties in getting the value of the objects with repeated elements. Specifically, I need to get the value of spacing of pixels in the following excerpt from xml.
    <DICOM_OBJECT>
    ..
         <DECIMAL_STRING tag="00181063" definer="DICOM" name="Frame Time" offset="900" length="2">0.0</DECIMAL_STRING>
         <CODE_STRING tag="0018106A" definer="DICOM" name="Synchronization Trigger" offset="910" length="10">NO TRIGGER</CODE_STRING>
    ..
         <DECIMAL_STRING tag="00280030" definer="DICOM" name="Pixel Spacing" offset="1660" length="22">0.003562</DECIMAL_STRING>
         <DECIMAL_STRING tag="00280030" definer="DICOM" name="Pixel Spacing" offset="1660" length="22">0.003562</DECIMAL_STRING>
         <UNSIGNED_SHORT tag="00280100" definer="DICOM" name="Bits Allocated" offset="1690" length="2">8</UNSIGNED_SHORT>
        <UNSIGNED_SHORT tag="00280101" definer="DICOM" name="Bits Stored" offset="1700" length="2">8</UNSIGNED_SHORT>
    ..
    </DICOM_OBJECT>
    Normally, I use the following query to get the value of spacing of pixels:
     select EXTRACTVALUE(t.dicom.metadata
                          ,'/DICOM_OBJECT/*[@name="Pixel Spacing"]'
                         ,'xmlns=http://xmlns.oracle.com/ord/dicom/metadata_1_0')  scale_factor
       from my_dicom_object t
    It works, but not when there are two elements. Then I get the error: "ORA-19025: EXTRACTVALUE returns the value of a single node.


    All I really need is to get the value of the first node with the name of "spacing of pixels. Despite the many examples available to do with traditional xml paths, I was unable to find an example that makes using XPATH search strings rather than direct tag structure.

    Can someone give an example?

    Thank you!

    Published by: rcdev on August 10, 2009 15:20

    All I really need is to get the value of the first node with the name of "spacing of pixels.

    This? :

    select EXTRACTVALUE(t.dicom.metadata
                          ,'/DICOM_OBJECT/*[@name="Pixel Spacing"][1]'
                         ,'xmlns=http://xmlns.oracle.com/ord/dicom/metadata_1_0')  scale_factor
       from my_dicom_object t
    

Maybe you are looking for