XMLText

XMLTEXT 函數會傳回 XML 值,其中包含 string-expression的值。

讀取語法圖跳過視覺化語法圖XMLTEXT(字串表示式 )
字串表示式
傳回內建字元或圖形字串值的表示式。 它不能是 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.
    Note that the '&' sign is mapped to '&' when the text is serialized.
  • 搭配使用 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>