Purpose
EXTRACTVALUE() extracts a value from an XML string using XPath notation.
Syntax
EXTRACTVALUE(xml_frag, xpath_expr)
Parameters
| Parameter | Description |
|---|---|
| xml_frag | The XML string, which can be an XML document or fragment. |
| xpath_expr | The XPath expression used for value extraction. |
Return type
The return type is LONGTEXT.
Examples
Multiple matched results are separated by spaces.
Call the
EXTRACTVALUE()function to extract values from the given XML string<a><b>x</b><b>y</b></a>on the XPath/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 when no matched results are found.
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