Team Fly | ![]() ![]() |
<product><name>Comic Book Heroes</name></product> <product><name>Finding Fido</name></product> <product><name>Xtend Memory</name></product> <product><name>Extension Cable</name></product> <product><name>Adventures with Numbers</name></product> <product><name>Fly Fishing</name></product> </ProdCategory> . . . . . . </Products>
Now that we have our XML documents loaded into the Oracle Database 10g, we will need a way to update them. The updatexml() function updates an attribute value, node, text node, or node tree for any XML document. The target for the update operation is identified using an XPath expression. The following listing shows how to update the XML document stored in a column defined as an XMLType:
update purchase_order set po_file = updateXML (PurchaseOrder, '/ PurchaseOrder/Requestor/text()', 'Speedo') where po_no = 67
In the previous listing, the updatexml() function is passed three arguments:
PurchaseOrder The document name (or root element) being updated
PurchaseOrder/Requestor The node to be updated
Speedo The value of the node value to be changed
Note the use of XPath syntax in this function. The path '/PurchaseOrder/Requestor/text()' specifies that we want to update the text in the PurchaseOrder document's Requestor field. The third argument to update XML specifies the new value for that text. This is an in-place update, making it a very efficient operation. XML DB Repository does not need to reconstruct the entire XML document being changed. Because the schema is registered, XML DB Repository is able to rewrite this query in such a way that only the web site attribute in the underlying object structure is touched.
Updating XML documents stored within a table defined by XMLType is a little different. With no column to set within our update statement, Oracle Database 10g allows us to define the object we would like to update by using the value() function. The following list shows an example of the SQL with the value() function.
Team Fly | ![]() ![]() |