This function updates the scalar
value of the XML tag in an XML document or an XML Element,
which passed as an argument by the user.
The prototype for defining the
UPDATEXML function is shown below,
UPDATEXML(<XML_Document> | <XML_Element>,
<XPath_Expression>, <Scalar_value>)
The
Pages tag from
the parent document is updated to 30 from 25 using this
function as shown below,
UPDATE book_store
SET book_details_xml=updatexml(book_details_xml,'/Rack1/Pages/text()',30)
WHERE book_id
=1001;
After the update is performed, the
changes can be verified by using the EXTRACTVALUE function
as shown below,
select extractvalue(book_details_xml,'/Rack1/Pages')
from book_store;
Result:
30
-------------------------------------------------------------------------------------
UPDATEXML searches for an XPATHexpression and updates it.
SELECT
EXTRACT(
UPDATEXML
(
OBJECT_VALUE,
'//DETAILS[ENTRY="1291-01-01"]/ENTRY',
XMLELEMENT(ENTRY, TO_DATE('01-08-1291','DD-MM-YYYY'))
)
, '//CANTON[NAME="Uri"]'
) URI
FROM
WORLD;
URI
---------------------------------
< CANTON ID="UR">
<NAME>Uri</NAME>
<DETAILS>
<ENTRY>1291-08-01</ENTRY>
<LANGUAGE>German</LANGUAGE>
</DETAILS>
<
/CANTON>
In the WORLD table, each entry of
1291-01-01 is updated by a new date. In the latest versions
of Oracle, the XML dates are stored according to the XML
convention SYYYY‑MM‑DD for dates and
SYYYY‑MM‑DD't?HH24:MI:SSXFF for timestamps. In earlier
releases, the date was stored according to the NLS settings.
UPDATEXML can change any element of the
document.
SELECT
UPDATEXML
(
XMLTYPE
(
CURSOR
(
SELECT
*
FROM
DEPT
)
),
'//ROW[DEPTNO=10]/LOC',
XMLTYPE('<CLOSED/>')
) DEPT
FROM
DUAL;
DEPT
-----------------------------------
< ?xml
version="1.0"?>
< ROWSET>
<ROW>
<DEPTNO>10</DEPTNO>
<DNAME>ACCOUNTING</DNAME>
<CLOSED/>
</ROW>
<ROW>
<DEPTNO>20</DEPTNO>
<DNAME>RESEARCH</DNAME>
<LOC>DALLAS</LOC>
</ROW>
<ROW>
<DEPTNO>30</DEPTNO>
<DNAME>SALES</DNAME>
<LOC>CHICAGO</LOC>
</ROW>
<ROW>
<DEPTNO>40</DEPTNO>
<DNAME>OPERATIONS</DNAME>
<LOC>BOSTON</LOC>
</ROW>
< /ROWSET>
The location of department 10 is replaced by an
empty tag. The underlying table DEPT is not changed, only
the result set is modified.
|
|
|
Oracle Training from Don Burleson
The best on site
"Oracle
training classes" are just a phone call away! You can get personalized Oracle training by Donald Burleson, right at your shop!

|
|
|

|
|
Burleson is the American Team

Note:
This Oracle
documentation was created as a support and Oracle training reference for use by our
DBA performance tuning consulting professionals.
Feel free to ask questions on our
Oracle forum.
Verify
experience!
Anyone
considering using the services of an Oracle support expert should
independently investigate their credentials and experience, and not rely on
advertisements and self-proclaimed expertise. All legitimate Oracle experts
publish
their Oracle
qualifications.
Errata?
Oracle technology is changing and we
strive to update our BC Oracle support information. If you find an error
or have a suggestion for improving our content, we would appreciate your
feedback. Just
e-mail:
and include the URL for the page.
Copyright © 1996 - 2020
All rights reserved by
Burleson
Oracle ®
is the registered trademark of Oracle Corporation.
|
|