0

Can someone help on how go i extract all the RefID? And what correct datatype will i use? Here's XML below:

<?xml version="1.0" encoding="UTF-8"?>
<Query xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="OutputQuery">
 <OutputOption>
  <RefId>
     <long>9474841</long>
     <long>9436906</long>
     <long>9506794</long>
  </RefId>
 </OutputOption>
</Query>

Output:

RefID
-----
9474841
9436906
9506794

1 Answer 1

0

This query should give you what you need:

select RefId
from
  xmltable(
    '/Query/OutputOption/RefId/long'
    passing xmltype(
      q'[<?xml version="1.0" encoding="UTF-8"?>
<Query xmlns:xsd="http://www.w3.org/2001/XMLSchema" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:type="OutputQuery">
  <OutputOption>
    <RefId>
       <long>9474841</long>
       <long>9436906</long>
       <long>9506794</long>
    </RefId>
  </OutputOption>
</Query>
      ]'
    )
    columns RefId number path '/'
  )
;

The data type that you will need is XMLTYPE.

Sign up to request clarification or add additional context in comments.

2 Comments

I am still searching for a good place to learn about using XML queries. Do you have any recommendations?
Tim Hall's oracle-base.com is a great site for reference. Then Oracle's official documentation.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.