XMLTEXT 标量函数 (scalar function)

XMLTEXT函数返回一个XML值,其中包含一个文本节点,该节点包含参数的值。

阅读语法图跳过可视化语法图XMLTEXT(字符串表达式 )

该模式是 SYSIBM。

字符串表达式
返回非位数据内置字符或图形字符串值的表达式。 当结果字符串转换为 UTF-8 时,其中任何字符都必须为有效的XML 1.0 字符。

如果字符串表达式为空字符串,则返回一个空文本节点。

函数的输出结果是一个XML值。

结果可以为空值;如果参数为空值,那么结果为空值。

示例1: 以下示例返回一个XML值,其中包含一个包含指定值的文本节点:
  SELECT XMLTEXT('The stock symbol for Johnson&Johnson is JNJ.') AS "Result"
     FROM SYSIBM.SYSDUMMY1;
结果看起来与以下结果相似:
Result
---------------------------------------------------

The stock symbol for Johnson&Johnson is JNJ.
示例2: XMLTEXT函数使XMLAGG函数能够构建混合内容,如下例所示:
 SELECT XMLELEMENT(NAME "para",
         XMLAGG(XMLCONCAT( XMLTEXT( plaintext),
                            XMLELEMENT( NAME "emphasis",
                            emphtext ))
                  ORDER BY seqno ), '.' ) as "result"
    FROM T;
假设表T的内容如下例所示:
seqno    plaintext                                          emphtext
-----    -------------------------------------------------  ----------------
1        This query shows how to construct                  mixed content
2        using XMLAGG and XMLTEXT. Without                  XMLTEXT
3        XMLAGG cannot group text nodes with other nodes,   mixed content
         therefore, cannot generate
结果如下:
result
--------------------------------------------------------------------------
<para>This query shows how to construct <emphasis>mixed content</emphasis>
using XMLAGG and XMLTEXT. Without <emphasis>XMLTEXT</emphasis>, XMLAGG
cannot group text nodes with other nodes, therefore, cannot generate
<emphasis>mixed content</emphasis>.</para>