DB2 Version 9.7 for Linux, UNIX, and Windows

XMLROW scalar function

The XMLROW function returns an XML value with a single XQuery document node containing one top-level element node.

Read syntax diagramSkip visual syntax diagram
              .-,-------------------------------------.   
              V                                       |   
>>-XMLROW--(----expression--+-----------------------+-+--------->
                            '-AS-- qname-identifier-'     

>--+------------------------------------------+--)-------------><
   |         .------------------------------. |      
   |         V  (1)    .-ROW-- "row"----.   | |      
   '-OPTION----------+-+-ROW-- row-name-+-+-+-'      
                     '-AS ATTRIBUTES------'          

Notes:
  1. The same clause must not be specified more than once.

The schema is SYSIBM. The function name cannot be specified as a qualified name.

expression
The content of each generated XML element node is specified by an expression. The data type of the expression cannot be a structured type (SQLSTATE 42884). The expression can be any SQL expression. If the expression is not a simple column reference, an element name must be specified.
AS qname-identifier
Specifies the XML element name or attribute name as an SQL identifier. The qname-identifier must be of the form of an XML qualified name, or QName (SQLSTATE 42634). See the W3C XML namespace specifications for more details on valid names. If the name is qualified, the namespace prefix must be declared within the scope (SQLSTATE 42635). If qname-identifier is not specified, expression must be a column name (SQLSTATE 42703). The element name or attribute name is created from the column name using the fully escaped mapping from a column name to an QName.
OPTION
Specifies additional options for constructing the XML value. If no OPTION clause is specified, the default behavior applies.
AS ATTRIBUTES
Specifies that each expression is mapped to an attribute value with column name or qname-identifier serving as the attribute name.
ROW row-name
Specifies the name of the element to which each row is mapped. If this option is not specified, the default element name is "row".

Notes

By default, each row in the result set is mapped to an XML value as follows:

Examples

Assume the following table T1 with columns C1 and C2 that contain numeric data stored in a relational format:

C1          C2
----------- -----------
          1           2
          -           2
          1           -
          -           -

  4 record(s) selected.