Skip to main content
Version: V1.0.0

EXTRACTVALUE

Description

This function is used to extract the value of a specified path from an XML string.

Syntax

EXTRACTVALUE(xml_frag, xpath_expr)

Parameters

ParameterDescription
xml_fragThe XML string to extract the value from. It can be an XML document or a fragment.
xpath_exprThe XPath expression specifying the path of the value to extract.

Return Type

The return type is LONGTEXT.

Examples

  • Multiple results are separated by spaces.

    Use the EXTRACTVALUE function 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.

    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 set (0.001 sec)
  • If no results are found, an empty string is returned.

    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 (0.001 sec)