Purpose
This function is used to extract the value at a specified path from an XML string.
Syntax
EXTRACTVALUE(xml_frag, xpath_expr)
Parameters
Field |
Note |
|---|---|
| xml_frag | The specified XML string, which can be an entire XML document or a fragment. |
| xpath_expr | Specify the XPath expression for the path of the value to extract. |
Return type
The return type is LONGTEXT.
Examples
Separate multiple matches with 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>. The path of the node to be extracted is/a/b.obclient [test_db]> SELECT EXTRACTVALUE('<a><b>x</b><b>y</b></a>', '/a/b');The return result is as follows:
+-------------------------------------------------+ | EXTRACTVALUE('<a><b>x</b><b>y</b></a>', '/a/b') | +-------------------------------------------------+ | x y | +-------------------------------------------------+ 1 row in setAn empty string is returned if no results are matched.
obclient [test_db]> SELECT EXTRACTVALUE('<a><b>x</b><b>y</b></a>', '/a/c');The return result is as follows:
+-------------------------------------------------+ | EXTRACTVALUE('<a><b>x</b><b>y</b></a>', '/a/c') | +-------------------------------------------------+ | | +-------------------------------------------------+ 1 row in set