1

I get the following XML from a request:

<records>
  <record>
    <field name="code" value="1"/>
    <field name="dexcription" value="MyName"/>
    <field name="id" value="666">
  </record>
  <record>
    <field name="code" value="2"/>
    <field name="dexcription" value="MyName"/>
  </record>
  ...
</records>

The first record was processed successfully, returning the element "id"; the second was not, and so returned without this element.

I need to write an XML SQL query based returning these two columns ("code" and "id"), but only records that were processed successfully. I tried to use XMLType, but it still fails. Can anyone help me?

Thanks in advance, and sorry for my "googled" English.

1
  • It's not clear what you're trying to do, what you've tried, and what behaviour you're seeing. Perhaps some sample code, and what error you're getting, would help. Commented May 31, 2012 at 3:20

1 Answer 1

1

I found the solution:

SELECT EXTRACT (COLUMN_VALUE, '/record/field[@name="code"]/@value').GETSTRINGVAL () AS CODE,
       EXTRACT (COLUMN_VALUE, '/record/field[@name="id"]/@value').GETSTRINGVAL () AS ID
  FROM TABLE (XMLSEQUENCE (XMLTYPE (:XXML).EXTRACT ('/records/record')))
 WHERE EXTRACT (COLUMN_VALUE, '/record/field[@name="id"]') IS NOT NULL
Sign up to request clarification or add additional context in comments.

1 Comment

If you are on Oracle10 or above, you'd want to switch to XMLTable(...) instead of TABLE(XMLSequence(...)). Shorter and clearer syntax.

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.