xmloracle-databaseupdatexml

Oracle: how to add a text node into an existing element


In Oracle, you can write:

update t
set xml = updateXML(xml, '/a/b/text()', 'gaga')

This works only if you already have some text in the <b> element. How to update the document and "add some text" in <b> if the document in the database looks like:

<a>
    <b/>
</a>

Solution

  • Here is one way to do it:

    update t
    set xml = updateXML(xml, '/a/b', XMLType('<b>gaga</b>'))
    

    I don't find this very elegant, but I am not sure you can do better.