Zirus
Zirus

Reputation: 1

oracle xml parsing with multi rows

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

Upvotes: 0

Views: 331

Answers (1)

Alex Poole
Alex Poole

Reputation: 191265

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

Upvotes: 2

Related Questions