Updating XMLTypes

The easiest way to update an XMLType is to use the updateXML() function. The following is an example of updateXML() (update_xmltype_updatexml.sql):

Listing 2-13 Updating XMLTypes with UpdateXML()

UPDATE contact_xsxtbl SET object_value =

updateXML()(object_value,

‘/ns:contact/ns:first_name/text()’,‘John Jr.’, ‘xmlns:ns=“http://xmlbook.com/sample/contact.xsd”’)

WHERE XMLExists(‘declare default element namespace “http://xmlbook.com/sample/contact.xsd”; $d/contact[first_name=“John”]’ passing object_value as “d”);

Another way to update XMLType is to use the XMLPatch() function (update_xmltype_ xmlpatch.sql):

Listing 2-14 Using XMLPatch() to Update XMLTypes

update contact_xsxtbl set object_value=XMLPatch(object_value,

XMLType(‘<xd:xdiff ...

Get Oracle Database 11g Building Oracle XML DB Applications now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.