0

query from xml not return rows.

I running this query but not return rows.

The my xml is :

<?xml version="1.0" encoding="UTF-8"?>
<ns0:testata xmlns:ns0="http://siete">
  <ns0:product>
    <ns0:YEAR>2019</ns0:YEAR>
    <ns0:PERIOD>1</ns0:PERIOD>
  </ns0:product>
  <ns0:product>
    <ns0:YEAR>2019</ns0:YEAR>
    <ns0:PERIOD>2</ns0:PERIOD>
  </ns0:product>
</ns0:testata>

My query is

FROM XMLTABLE('/testata/product'  
         PASSING   
              (select  xmltype(t.XML1) doc
                 from tb_test t)
         COLUMNS  
             name  varchar2(4)    PATH './YEAR'
     ) xmlt   

0 rows

please help me

1 Answer 1

2

Your XML document has a namespace, so you either need to wildcard the nodes in your XMLTable call, or - preferably - supply the same namespace information and prefixes:

-- CTE for sample data
with tb_test (xml1) as (select '<?xml version="1.0" encoding="UTF-8"?>
<ns0:testata xmlns:ns0="http://siete">
  <ns0:product>
    <ns0:YEAR>2019</ns0:YEAR>
    <ns0:PERIOD>1</ns0:PERIOD>
  </ns0:product>
  <ns0:product>
    <ns0:YEAR>2019</ns0:YEAR>
    <ns0:PERIOD>2</ns0:PERIOD>
  </ns0:product>
</ns0:testata>' from dual
)
-- actual query
select x.year
from tb_test t
cross join xmltable(
  xmlnamespaces('http://siete' as "ns0"),
  '/ns0:testata/ns0:product'
  passing xmltype(t.xml1)
  columns year number path 'ns0:YEAR'
) x;

      YEAR
----------
      2019
      2019
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.