XMLTEXT

XMLTEXT 函数返回包含 string-expression值的 XML 值。

读取语法图跳过可视语法图XMLTEXT(string-表达式 )
字符串表达式
返回内置字符或图形字符串的值的表达式。 它不能是 CHAR 或 VARCHAR 位数据。

此函数的结果是 XML 值。 如果 string-expression 的结果可以为空,那么结果可以为空; 如果 string-expression 的结果为空,那么结果为空值。 如果 string-expression 的结果是空字符串,那么结果值为空文本。

示例

  • 创建简单 XMLTEXT 查询。
      VALUES (XMLTEXT (
                'The stock symbol for Johnson&Johnson is JNJ.'))
    

    此查询将生成以下序列化结果:

    The stock symbol for Johnson&Johnson is JNJ.
    请注意,在文本序列化时,"&"符号会被映射为"&"。
  • 将 XMLTEXT 与 XMLAGG 配合使用以构造混合内容。 假定表 T 的内容如下所示:
  • SEQNO  PLAINTEXT                                                     EMPHTEXT
    -----  ----------------------------------------------------------    ----------
    1      This query shows how to construct                             mixed content
    2       using XMLAGG and XMLTEXT. Without                            XMLTEXT
    3      , XMLAGG will not have text nodes to group with other nodes,  mixed content
           therefore, cannot generate             
    SELECT XMLELEMENT(NAME "para", 
                  XMLAGG(XMLCONCAT(
                                     XMLTEXT(PLAINTEXT),
                                     XMLELEMENT(
                                          NAME "emphasis", EMPHTEXT))
                           ORDER BY SEQNO), '.') AS "result"
      FROM T
    此查询将生成以下结果:
    result
    ------------------------------------------------------------------------------
    <para>This query shows how to construct <emphasis>mixed content</emphasis>
    using XMLAGG and XMLTEXT. Without <emphasis>XMLTEXT</emphasis>, XMLAGG
    will not have text nodes to group with other nodes, therefore, cannot generate
    <emphasis>mixed content</emphasis>.</para>