Update XML in Oracle using XMLUPDATE



I have an XML document like this one and I have to update value of The time of begin by new text. How to do this with XMLUPDATE function, i.e. what is the XPath expression?



<dok>
<dataSet>
<foo>bla bla</foo>
<field>START_DATE</field>
<label>The time of begin</label>
</dataSet>
<dataSet>
<bar>bla bla</bar>
<label>The time of end</label>
<field>END_DATE</field>
</dataSet>
</dok>


My first idea was like this one:



UPDATE MY_TABLE SET
XML_COLUMN = XMLUPDATE(XML_COLUMN, '/dok/dataSet/field/text()="START_DATE"/../label/text()', 'The date of start');


I don't like to use axis like following-sibling, because inside dataSet you may have various other elements in unknown order.


The rule shall be like: Update "label" at "dataSet" where "field" = 'START_DATE'


No comments:

Post a Comment