Feb 11, 2016

TIL - Parse XML in Oracle SQL using XMLTABLE with namespaces

XML

<foo xmlns="http://example.com/namespace">
  <bar>
    <baz>Value 01</baz>
    <qux>Value 02</qux>
  </bar>
  <bar>
    <baz>Value 11</baz>
    <qux>Value 12</qux>
  </bar>
</foo>

SQL Query

select x.*
   from HPLAN , XMLTABLE (
         xmlnamespaces (default 'urn:schemas-mcsfr-com:simulation'),
         '/simulation//echeance'
         passing xml_plan
         columns dateEcheance varchar2(20) path 'dateEcheance',  
                 montantEcheance varchar2(20) path 'montantEcheance'
        ) x;