I have some sample code as follows:
WITH xtbl AS
(SELECT 1 AS xtbl_id,
xmltype ('<node_root>
<node_1>12</node_1>
<node_2>233</node_2>
<node_3>223</node_3>
<node_4>234</node_4>
</node_root>') AS x
FROM Dual
UNION ALL
SELECT 2, xmltype ('<node_root>
<node_1></node_1>
<node_2>233</node_2>
<node_3>223</node_3>
<node_4>234</node_4>
</node_root>')
FROM Dual)
SELECT xtbl_id,
x,
Updatexml (x,
'/node_root/node_2',
NULL,
'/node_root/node_3',
NULL,
'/node_root/node_4',
NULL)
AS xcol
FROM xtbl
WHERE (SELECT node_1
FROM Xmltable ('node_root'
PASSING x
COLUMNS node_1 INTEGER PATH 'node_1'))
IS NOT NULL;
My requirement is that whenever /node_root/node_1 in column x is not null then replace the values for /node_root/node_2, /node_root/node_3 and /node_root/node_4 to null. The Updatexml function I have used in my SELECT query does the same.
The problem here is that Updatexml doesn't work in Oracle 12c. This is why I have used Xmltable in the subquery and it works perfect at filtering the data, but I am not able to replace the node values with null.
I tried looking at Oracle Docs for XQuery but couldn't understand how it can be helpful at replacing node values.
Kindly provide a descriptive example.