XML variables

An XML variable can be defined as a string or file reference variable. Regular XML variables and XML file reference variables can be defined in all host languages with a few exceptions.

  • REXX supports file reference variables for XML.
  • Java™ supports XML and file reference variables for XML.

XML variables can be declared as the following variable types:

Where XML variables are allowed, the meta-variable variable in a syntax diagram can refer to a regular variable or a file reference variable. Because these variables are not native data types in host programming languages, SQL extensions are used, and the precompilers generate the host language constructs that are necessary to represent each variable.

When it is possible to define a variable that is large enough to hold an entire XML value and the performance benefit of delaying the transfer of data from the server is not required, an XML file reference is not needed. However, it is often not acceptable to store an entire XML value in temporary storage due to host language restrictions, storage restrictions, or performance requirements. When storing an entire XML value at one time is not acceptable, portions of the value can be accessed, or the entire value can be stored in a file. When the entire value is stored in a file, an XML file reference can be used to access the data.

XML host variables can be declared as the following variable types:

  • XML AS CLOB(n)

    Declares a CLOB variable that contains XML data that is encoded in the CCSID for the variable.

  • XML AS DBCLOB(n)

    Declares a DBCLOB variable that contains XML data that is encoded in the graphic CCSID for the variable.

  • XML AS BLOB(n)

    Declares a BLOB variable that contains XML data that is encoded as specified within the data according to the XML 1.0 specification for determining encoding.

  • XML AS CLOB_FILE

    Declares a CLOB file reference variable that contains XML data that is encoded in the CCSID for the file reference variable.

  • XML AS DBCLOB_FILE

    Declares a DBCLOB file reference variable that contains XML data that is encoded in the CCSID for the file reference variable.

  • XML AS BLOB_FILE

    Declares a BLOB file reference variable that contains XML data that is encoded in the CCSID for the file reference variable.

See LOB or XML file reference variables for additional information about file reference variables.

Although the application XML variable declaration includes a LOB type specification, the variable declarations all are considered to be the XML data type, not the LOB type that is used in the application declaration. The application might also use non-XML variables in place of XML variables. For example, when a prepared statement is executed, the application might use a character variable to replace an XML parameter marker in the statement.

Although the XML data type is incompatible with all other data types, both XML and non-XML data types can be used for input to and output from XML data. Applications can use either XML variables, character variables, or binary string variables for input and output in SQL statements for XML data.

The following table summarizes the conversions built-in data types (including XML) to and from the supported variable data types within embedded applications. The built-in data types are specified in the rows. A Y indicates that the built-in data type can be assigned to or assigned from the variable type.
Table 1. Application variable compatibility with the built-in data types for applications that contain embedded SQL
built-in data type application variable data type
CHAR, VARCHAR, CLOB, CLOB_FILE GRAPHIC, VARGRAPHIC, DBCLOB, DBCLOB_FILE BINARY, VARBINARY, BLOB, BLOB_FILE XML AS CLOB, XML AS CLOB_FILE XML AS DBCLOB, XML AS DBCLOB_FILE XML AS BLOB, XML AS BLOB_FILE
CHAR Y Y        
VARCHAR Y Y        
CLOB Y Y        
GRAPHIC Y Y        
VARGRAPHIC Y Y        
DBCLOB Y Y        
BINARY     Y      
VARBINARY     Y      
BLOB     Y      
XML Y Y Y Y Y Y