XML Values

An XML value represents well-formed XML in the form of an XML document, XML content, or an XML sequence.

An XML value that is stored in a table as a value of a column defined with the XML data type must be a well-formed XML document. XML values are processed in an internal representation that is not comparable to any string value including another XML value. The only predicate that can be applied to the XML data type is the IS NULL predicate.

An XML value can be transformed into a serialized string value representing an XML document using the XMLSERIALIZE function. Similarly, a string value that represents an XML document can be transformed into an XML value using the XMLPARSE function. An XML value can be implicitly parsed or serialized when exchanged with application string and binary data types.

The XML data type has no defined maximum length. It does have an effective maximum length when treated as a serialized string value that represents XML which is the same as the limit for LOB data values. Like LOBs, there are also XML locators and XML file reference variables.

Restrictions when using XML values: With a few exceptions, you can use XML values in the same contexts in which you can use other data types. XML values are valid in:

  • CAST a parameter marker, XML, or NULL to XML
  • XMLCAST a parameter marker, XML, or NULL to XML
  • IS NULL predicate
  • COUNT and COUNT_BIG aggregate functions
  • COALESCE, IFNULL, HEX, LENGTH, CONTAINS, and SCORE scalar functions
  • XML scalar functions
  • A SELECT list without DISTINCT
  • INSERT VALUES clause, UPDATE SET clause, and MERGE
  • SET and VALUES INTO
  • Procedure parameters
  • User-defined function arguments and result
  • Trigger correlation variables
  • Parameter marker values for a dynamically prepared statement

XML values cannot be used directly in the following places. Where expressions are allowed, an XML value can be used, for example, as the argument of XMLSERIALIZE:

  • A SELECT list containing the DISTINCT keyword
  • A GROUP BY clause
  • An ORDER BY clause
  • A subselect of a fullselect that is not UNION ALL
  • A basic, quantified, BETWEEN, DISTINCT, IN, or LIKE predicate
  • An aggregate function with the DISTINCT keyword
  • A primary, unique, or foreign key
  • A check constraint
  • An index column

No host languages have a built-in data type for the XML data type.

For information on the XML data model and XML values, see SQL XML programming.

Determining the CCSID for XML

XML data can be defined with any EBCDIC single byte or mixed CCSID or a Unicode CCSID of 1208, 1200, or 13488. 65535 is not allowed as a CCSID for XML data. The CCSID can be explicitly specified when defining an XML data type. If it is not explicitly specified, the CCSID will be assigned using the value of the SQL_XML_DATA_CCSID QAQQINI file option. If this value has not been set, the default is 1208 (UTF-8).

The CCSID will be established for XML data types used in SQL schema statements when the statement is run.

XML host variables that do not have a DECLARE VARIABLE that assigns a CCSID will have their CCSID assigned as follows:.
  • If it is XML AS DBCLOB, the CCSID will be 1200.
  • If it is XML AS CLOB and the SQL_XML_DATA_CCSID QAQQINI value is 1200 or 13488, the CCSID will be 1208.
  • Otherwise, the SQL_XML_DATA_CCSID QAQQINI value will be used as the CCSID.

Since all implicit and explicit XMLPARSE functions are performed using UTF-8 (1208) defining data in this CCSID removes the need to convert the data to UTF-8.