Extract value of child from xmltable

There is a big xml , from which i need to extract 2 values. Belowis the snippet.
There could be multiple Identifier tags so i need to find the one which has Scheme= value1 and print its value and the other child's value of the same tag.
I am not able to get to the second child value. Please suggest.

<Identifier>
  <issue Scheme="value1">A</issue>
  <Id IdScheme="value2">B</Id>
</Identifier>

with mydata as
( select xml_data xx from table1 where id = hextoraw('FFA2F897DD7C30E030CEB15088FE')
)  
select *
from  mydata,
xmltable(xmlnamespaces(  'http://www.fpml.org/FpML-5/recordkeeping' as "n3"),
'/n3:root/*//n3:Identifier/n3:issue[@Scheme=''value1'']'                
                                PASSING mydata.xx
                                columns usi    varchar2(200)  PATH '.'    -- Prints A
                                       ,usi_v  varchar2(200)  PATH '/..//n3:Id'  --Prints Null
                                    );
Nakul ChawlaAsked:
Who is Participating?
 
sdstuberConnect With a Mentor Commented:
I don't have your table or data, so I made up my own.
For simplicity I left out namespace in my example, but you should be able to add that back in.

If not, post a full example xml and I can adjust as needed

DROP TABLE table1 PURGE;

CREATE TABLE table1
(
    xml_data   XMLTYPE,
    id         RAW(14)
);

INSERT INTO table1
     VALUES (xmltype('<whatever>
<Identifier>
  <issue Scheme="valueX">A</issue>
  <Id IdScheme="value2">B</Id>
</Identifier>
<Identifier>
  <issue Scheme="valueY">A</issue>
  <Id IdScheme="value2">B</Id>
</Identifier>
<Identifier>
  <issue Scheme="valueZ">A</issue>
  <Id IdScheme="value2">B</Id>
</Identifier>
<Identifier>
  <issue Scheme="value1">A</issue>
  <Id IdScheme="value2">B</Id>
</Identifier>
<Identifier>
  <issue Scheme="value9999">A</issue>
  <Id IdScheme="value2">B</Id>
</Identifier>
</whatever>'  ), HEXTORAW('FFA2F897DD7C30E030CEB15088FE'));

WITH mydata
     AS (SELECT xml_data xx
           FROM table1
          WHERE id = HEXTORAW('FFA2F897DD7C30E030CEB15088FE'))
SELECT x.*
  FROM mydata,
       XMLTABLE('//Identifier/issue[@Scheme="value1"]/parent::node()'
                PASSING mydata.xx
                COLUMNS usi VARCHAR2(20) PATH './issue/text()', usi_v VARCHAR2(200) PATH './Id/text()') x;

Open in new window

1
 
Nakul ChawlaAuthor Commented:
Oh yes it worked. I just didnt know how to go to the parent node. The /parent::node() helped.
Thanks a lot.
0
 
Nakul ChawlaAuthor Commented:
Hey need further help.
So now i am able to fetch the values but this has to be stored in a another table. I need to fetch value for around 15 million rec.
The explain plan gives a collection iterator pickler fetch and the query keeps on running.
create table temp as
with mydata as
( select  * from temp_3_a_pp
)  
select *
from  mydata,
xmltable(
'//Identifier/issuer [@Scheme="value1"]/parent::node()'                
                                PASSING mydata.xx
                                columns usi varchar2(200)  PATH './issuer'
                                , usi_v varchar2(200)  PATH './Id '

        );      

Plan Hash Value  :

-----------------------------------------------------------------------------------------------------------------------
| Id | Operation                              | Name                  | Rows        | Bytes         | Cost     | Time |
-----------------------------------------------------------------------------------------------------------------------
|  0 | CREATE TABLE STATEMENT                 |                       | 12695914464 | 1104544558368 | 39065237 |      |
|  1 |   LOAD AS SELECT                       | TEMP_CFTC_USI         |             |               |          |      |
|  2 |    OPTIMIZER STATISTICS GATHERING      |                       | 12695914464 | 1104544558368 |   549266 |      |
|  3 |     NESTED LOOPS                       |                       | 12695914464 | 1104544558368 |   549266 |      |
|  4 |      PX COORDINATOR                    |                       |             |               |          |      |
|  5 |       PX SEND QC (RANDOM)              | :TQ10000              |     1554348 |     132119580 |    19243 |      |
|  6 |        PX BLOCK ITERATOR               |                       |     1554348 |     132119580 |    19243 |      |
|  7 |         TABLE ACCESS FULL              | TEMP_3_A_PP           |     1554348 |     132119580 |    19243 |      |
|  8 |      COLLECTION ITERATOR PICKLER FETCH | XQSEQUENCEFROMXMLTYPE |        8168 |         16336 |       26 |      |
-----------------------------------------------------------------------------------------------------------------------
0
Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
sdstuberCommented:
you have no where clause on temp_3_a_pp, so you're going to do a full table scan of it and read all of the xml of every row.

If you can specify the path more explicitly than //Identifier,  that will make the searches more efficient.

Also, is it a true statement that there will only be one node you want? If so, you can tune the path for that as well.

For example, with my simple example above, this is a more efficient search to get only the first matching node.

WITH mydata
     AS (SELECT xml_data xx
           FROM table1
          WHERE id = HEXTORAW('FFA2F897DD7C30E030CEB15088FE'))
SELECT x.*
  FROM mydata,
       XMLTABLE('(/whatever/Identifier/descendant::issue[@Scheme="value1"])[1]/parent::node()'
                PASSING mydata.xx
                COLUMNS usi VARCHAR2(20) PATH './issue/text()', usi_v VARCHAR2(200) PATH './Id/text()') x;

Open in new window



the "PICKLER" is the XMLTABLE.    When you select from any table function in oracle, the operation of extracting data from the function into a queryable result set is the PICKLER.  I don't know why they called it that; but that's the operation.
0
 
Nakul ChawlaAuthor Commented:
Can't do that as the identifier tab is sometimes under a different tab. Depending on the type of xml is sent  or received. So there is some extra parent element for it.
Yes only the issue and Id values needs to be fetched from xml, for all the records in temp_3_a_pp. Actually this is a temp table which has been created from the main table whose xml needs to be looked upon.
Any suggestion?
0
 
sdstuberCommented:
if the Identifier node will have variable depth then // will be needed
but you can still apply a filter that will stop searching after it finds the first matching node, assuming you only want one for each xml doc.

SELECT x.*
  FROM mydata,
       XMLTABLE('(//Identifier/descendant::issue[@Scheme="value1"])[1]/parent::node()'
                PASSING mydata.xx
                COLUMNS usi VARCHAR2(20) PATH './issue/text()', 
                                   usi_v VARCHAR2(200) PATH './Id/text()') x;

Open in new window

0
 
nk studentCommented:
this still takes a collection iterator pickler fetch and it is running for more than an hour
0
 
sdstuberCommented:
nk student - how do you know? Do you have the asker's data?

Also, the pickler is unavoidable using xmltable.
As I stated earlier, the pickler operation is what pulls data from xmltable as a result set.
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.