Join Oracle Xquery

53 Views Asked by At

I have a Oracle table with a XML field and another table which contains a list of TAG which I need to find on first table. On second table I have another field to remap TAGs. The second table may have also null values.

Example:

Table1

MY_XML
<TAG1>1</TAG1><TAG2>2</TAG2><TAG3>3</TAG3>

Table2

XML_TAG_NAME XML_NEW_TAG_NAME
TAG1 NEW_TAG1
null null
TAG3 NEW_TAG3

the result which I need should be:

<NEW_TAG1>1</NEW_TAG1><NEW_TAG_3>3</NEW_TAG_3>

I was trying with Xquery but I got lost. I don't know how to join data from both tables and how to exclude null values from Table2

select * from Table1 t
join  XMLTable('
    for $x in //descendant::*
    for $i in fn:collection("oradb:/MY_USER/TABLE2")/ROW
    
    
    return $i'
    passing case when t.MY_XML is null then null else xmltype ('<?xml version="1.0" encoding="iso-8859-1" ?>'||t.MY_XML)end
    ) on 1=1;
0

There are 0 best solutions below