Collections:
UPDATEXML() - Updating Child Element in XML
How to update a child element in an XML document at a given location using the UPDATEXML() function?
✍: FYIcenter.com
UPDATEXML(xml, path, subxml) is a MySQL built-in function that
updates a child element in an XML document at a given location.
For example:
SET @xml = 'XY'; SELECT UPDATEXML(@xml, '/a', 'Z '); +-----------------------------------+ | UPDATEXML(@xml, '/a', 'Z ') | +-----------------------------------+ |Z | +-----------------------------------+ SELECT UPDATEXML(@xml, '//b', 'Z '); +------------------------------------+ | UPDATEXML(@xml, '//b', 'Z ') | +------------------------------------+ | XY | +------------------------------------+ SELECT UPDATEXML(@xml, '//b[2]', 'Z '); +---------------------------------------+ | UPDATEXML(@xml, '//b[2]', 'Z ') | +---------------------------------------+ | XZ | +---------------------------------------+
Note that variables used in the location path must be escaped with the '$' prefix. For example,
SET @i =1; SELECT UPDATEXML(@xml, '//b[$@i]', 'Z '); +-----------------------------------------+ | UPDATEXML(@xml, '//b[$@i]', 'Z ') | +-----------------------------------------+ |Z Y | +-----------------------------------------+
Reference information of the UPDATEXML() function:
UPDATEXML(xml, path, subxml): newxml Updates a child element in an XML document at a given location. Arguments, return value and availability: xml: Required. The XML document to be updated. path: Required. The location path where the existing element is updated. subxml: Required. The XML element to replace with. newxml: Return value. The updated XML document. Available since MySQL 4.0.
⇒ VALUES() - Column Value for "ON DUPLICATE KEY UPDATE"
⇐ SLEEP() - Holding Statement Execution
2023-12-19, 963🔥, 0💬
Popular Posts:
How to run Queries with SQL Server Management Studio Express in SQL Server? 1. Launch and connect SQ...
How To Replace Given Values with NULL using NULLIF() in SQL Server Transact-SQL? Sometime you want t...
How To Verify a User name with SQLCMD Tool in SQL Server? The quickest way to verify a user name in ...
How to continue to the next iteration of a WHILE loop in SQL Server Transact-SQL? How to use CONTINU...
Is SQL Server Transact-SQL case sensitive? No. Transact-SQL is not case sensitive. Like the standard...