Purpose
The UPDATEXML function updates the value of a node in an XMLType instance by using an XPath expression and a value expression. You can specify one or more XPath and value pairs to update the values of the nodes found by the XPath expressions in the specified order.
Syntax
UPDATEXML
(XMLType_instance,
XPath_string, value_expr
[, XPath_string, value_expr ]...
[, namespace_string ]
)
Parameters
| Parameter | Description |
|---|---|
| XMLType_instance | The XMLType instance to be updated. You can specify an XMLType column or an expression that returns an XMLType value. |
| XPath_string | The XPath expression that specifies the node to be updated. |
| value_expr | The value to be updated. The value can be of the XMLType, scalar, CLOB, or NULL data type. |
| namespace_string | The namespace of the node to be updated. |
Return value
The function returns an XMLType value.
Considerations
- You can specify a NULL, scalar, or XMLType value for
value_expr. - You can specify a namespace for the node to be updated by using the
namespace_stringparameter.
Examples
obclient> SELECT UPDATEXML(XMLPARSE(CONTENT '<root><a>aaa</a></root>'), '/root/a/text()', 'bbb') RES FROM DUAL;
+------------------------------+
| RES |
+------------------------------+
| <root>
<a>bbb</a>
</root>
|
+------------------------------+
1 row in set
obclient> SELECT UPDATEXML(XMLPARSE(CONTENT '<root><a>aaa</a></root>'), '/root/a/text()', NULL) RES FROM DUAL;
+------------------------+
| RES |
+------------------------+
| <root>
<a/>
</root>
|
+------------------------+
1 row in set
obclient> SELECT UPDATEXML(XMLPARSE(CONTENT '<root><a>aaa</a></root>'), '/root/a/text()', XMLPARSE(content '<a>bbb</a>')) RES FROM DUAL;
+---------------------------------------------+
| RES |
+---------------------------------------------+
| <root>
<a>
<a>bbb</a>
</a>
</root>
|
+---------------------------------------------+
1 row in set
obclient> SELECT UPDATEXML(XMLPARSE(CONTENT '<root a1="aaa"><a>aaa</a></root>'), '/root/@a1', 'bbb') RES FROM DUAL;
+---------------------------------------+
| RES |
+---------------------------------------+
| <root a1="bbb">
<a>aaa</a>
</root>
|
+---------------------------------------+
1 row in set
obclient> SELECT UPDATEXML(XMLPARSE(CONTENT '<root a1="aaa"><a>aaa</a></root>'), '/root/@a1', NULL) RES FROM DUAL;
+------------------------------------+
| RES |
+------------------------------------+
| <root a1="">
<a>aaa</a>
</root>
|
+------------------------------------+
1 row in set
obclient> SELECT UPDATEXML(XMLPARSE(CONTENT '<root a1="aaa"><a>aaa</a></root>'), '/root/@a1', XMLPARSE(CONTENT '<a>a1</a>')) RES FROM DUAL;
+------------------------------------------+
| RES |
+------------------------------------------+
| <root>
<a>a1</a>
<a>aaa</a>
</root>
|
+------------------------------------------+
1 row in set
obclient> SELECT UPDATEXML(XMLPARSE(CONTENT '<root><a>aaa</a></root>'), '/root/a', 'bbb') RES FROM DUAL;
+-------------------+
| RES |
+-------------------+
| <root>bbb</root>
|
+-------------------+
1 row in set
obclient> SELECT UPDATEXML(XMLPARSE(CONTENT '<a a1="a1" xmlns:f="ns1" xmlns="ns2"><c/>cccc</a>'), '/a', NULL, 'xmlns="ns2"') RES FROM DUAL;
+-------------------+
| RES |
+-------------------+
| <a xmlns="ns2"/>
|
+-------------------+
1 row in set (0.01 sec)
obclient> SELECT UPDATEXML(XMLPARSE(CONTENT '<root><a>aaa</a></root>'), '/root/a', xmltype('<b>bbb</b>')) RES FROM DUAL;
+------------------------------+
| RES |
+------------------------------+
| <root>
<b>bbb</b>
</root>
|
+------------------------------+
1 row in set
