Modifying XML Values

Learn how to modify XML values in MySQL.

Besides ExtractValue() for searching XML values, MySQL also offers the UpdateXML() function to—as the name suggests—update an existing XML value. While we could use an UPDATE statement to replace an XML value as a whole, the UpdateXML() function has the advantage that we can specifically update only parts of an XML document. We can also combine UpdateXML() with ExtractValue() for certain use cases.

The UPDATE statement

As with any kind of value, we can use an UPDATE statement to replace an XML value. For example, in a previous instance, we looked at the following catalog of books:

Get hands-on with 1400+ tech skills courses.