1

I am trying to extract values from XML data stored as NCLOB column in Oracle db table.

xml structure

<?xml version="1.0" encoding="UTF-8"?>
<root xmlns="http://example.com/FAS/DOC/2011/v3.0b" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance">
  <record xmlns="http://example.com/FAS/DOC/2011/v3.0b">
    <pdate xmlns="http://example.com/FAS/DOC/2011/v3.0b">2014-05-15</pdate>
  </record>
</root>

Query

select EXTRACTVALUE(XMLTYPE(nclob_column),'/root/record/pdate','xmlns="http://example.com/FAS/DOC/2011/v3.0b"') pdate1,
       EXTRACTVALUE(XMLTYPE(nclob_column),'/root/record/pdate') pdate2
from   nclob_table

Problem

The pdate1 does return the value, but pdate2 returns null. I cannot use the third parameter of EXTRACTVALUE() to specify the xmlns attribute value as that changes on every row/record. So I get the value for one row but null for all others.

How do I extract the value without specifying the attribute?

Thanks.

1 Answer 1

0

If you can guarantee that the namespace doesn't matter for selecting an element in this case, you can use local-name() to match element only by it's local name, ignoring the namespace :

select EXTRACTVALUE(
            XMLTYPE(nclob_column),
            '/*[local-name()="root"]/*[local-name()="record"]/*[local-name()="pdate"]'
        ) pdate
from   nclob_table

SQL Fiddle

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

Comments

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.