Purpose
This function is used to extract the value of a specified path from an XML string.
Syntax
EXTRACTVALUE(xml_frag, xpath_expr)
Parameters
Field |
Description |
|---|---|
| xml_frag | The XML string to extract the value from. It can be an XML document or a fragment. |
| xpath_expr | The path (XPath) expression to extract the value. |
Return type
The return type is LONGTEXT.
Examples
If multiple results are matched, they are separated by spaces.
Use the
EXTRACTVALUEfunction to extract the value of a specific node from the given XML string<a><b>x</b><b>y</b></a>, where the node path is/a/b.obclient [test_db]> SELECT EXTRACTVALUE('<a><b>x</b><b>y</b></a>', '/a/b');The result is as follows:
+-------------------------------------------------+ | EXTRACTVALUE('<a><b>x</b><b>y</b></a>', '/a/b') | +-------------------------------------------------+ | x y | +-------------------------------------------------+ 1 row in setIf no results are matched, an empty string is returned.
obclient [test_db]> SELECT EXTRACTVALUE('<a><b>x</b><b>y</b></a>', '/a/c');The result is as follows:
+-------------------------------------------------+ | EXTRACTVALUE('<a><b>x</b><b>y</b></a>', '/a/c') | +-------------------------------------------------+ | | +-------------------------------------------------+ 1 row in set
