XML assignments

The following rules apply when the assignment target is XML.

The general rule for XML assignments is that only an XML value can be assigned to an XML column or an XML variable. There are exceptions to this rule as follows:

  • Processing of input XML variables: This is a special case of the XML assignment rule because the variable is based on a string value. To make the assignment to XML within SQL, the string value is implicitly parsed into an XML value using the setting of the CURRENT IMPLICIT XMLPARSE OPTION special register. This determines whether to preserve or to strip whitespace, unless the variable is an argument of the XMLVALIDATE function which always strips unnecessary whitespace.
  • Assigning strings to input parameter markers of data type XML: If an input parameter marker has an implicit or explicit data type of XML, the value assigned to that parameter marker could be a character string variable, graphic string variable, or binary string variable. In this case, the string value is implicitly parsed into an XML value using the setting of the CURRENT IMPLICIT XMLPARSE OPTION special register. This determines whether to preserve or to strip whitespace, unless the parameter marker is an argument of the XMLVALIDATE function which always strips unnecessary whitespace.
  • Assigning strings directly to XML columns in data change statements: If assigning directly to a column of type XML in a data change statement, the assigned expression can also be a character string, a graphic string, or a binary string. In this case, the result of XMLPARSE (DOCUMENT expression STRIP WHITESPACE) is assigned to the target column. The supported string data types are defined by the supported arguments for the XMLPARSE function. This exception also applies to SQL parameters of type XML.
  • Assigning XML to strings on retrieval: If retrieving XML values into variables using a FETCH or SELECT INTO in embedded SQL, the data type of the variable can be CLOB, DBCLOB, or BLOB. The XML value is implicitly serialized to a string encoded in the variable's CCSID. If using other application programming interfaces (such as CLI, JDBC, or .NET), XML values can be retrieved into the character, graphic, or binary string types that are supported by the application programming interface. In all these cases, the XML value is implicitly serialized to a string encoded in the CCSID determined by the QAQQINI file as described in XML Values.

For the FETCH, SELECT INTO, SET, and VALUES INTO statements, character string, graphic string, or binary string values cannot be retrieved into XML variables. For the INSERT, UPDATE, MERGE, SET, VALUES INTO, and CALL statements, values in XML variables cannot be assigned to columns, SQL variables, or SQL parameters of a character, graphic, or binary string data type.