DB2 Version 9.7 for Linux, UNIX, and Windows

XMLATTRIBUTES scalar function

Read syntax diagramSkip visual syntax diagram
>>-XMLATTRIBUTES------------------------------------------------>

      .-,--------------------------------------------------.      
      V                                                    |      
>--(----attribute-value-expression--+--------------------+-+--)-><
                                    '-AS--attribute-name-'        

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

The XMLATTRIBUTES function constructs XML attributes from the arguments. This function can only be used as an argument of the XMLELEMENT function. The result is an XML sequence containing an XQuery attribute node for each non-null input value.

attribute-value-expression
An expression whose result is the attribute value. The data type of attribute-value-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 attribute name must be specified.
attribute-name
Specifies an attribute name. The name is an SQL identifier that must be in the form of an XML qualified name, or QName (SQLSTATE 42634). See the W3C XML namespace specifications for more details on valid names. The attribute name cannot be xmlns or prefixed with xmlns:. A namespace is declared using the function XMLNAMESPACES. Duplicate attribute names, whether implicit or explicit, are not allowed (SQLSTATE 42713).

If attribute-name is not specified, attribute-value-expression must be a column name (SQLSTATE 42703). The attribute name is created from the column name using the fully escaped mapping from a column name to an XML attribute name.

The data type of the result is XML. If the result of attribute-value-expression can be null, the result can be null; if the result of every attribute-value-expression is null, the result is the null value.

Examples:

Note: XMLATTRIBUTES does not insert blank spaces or new line characters in the output. All example output has been formatted to enhance readability.