Start of change

XMLAGG

The XMLAGG function returns an XML sequence containing an item for each non-null value in a set of XML values.

Read syntax diagramSkip visual syntax diagram
>>-XMLAGG--(--XML-expression -+---------------------------------------------+--)-><
                              |           .-,-----------------------------. |      
                              |           V                      .-ASC--. | |      
                              '-ORDER BY----sort-key-expression--+------+-+-'      
                                                                 '-DESC-'          

XML-expression
An expression that returns an XML value.
ORDER BY
Specifies the order of the rows from the same grouping set that are processed in the aggregation. If the ORDER BY clause is not specified, or if the ORDER BY clause cannot differentiate the order of the sort key value, the rows in the same grouping set are arbitrarily ordered.
sort-key-expression
Specifies a sort key value that is either a column name or an expression. The data type of the column or expression must not be a DATALINK or XML value.
The ordering is based on the values of the sort keys, which might or might not be used in XML-expression.
The sum of the length attributes of the sort-key-expressions must not exceed 32766-n bytes (where n is the number of sort-key-expressions specified that allow nulls).

If a collating sequence other than *HEX is in effect when the statement that contains the XMLAGG function is executed and the sort-key-expressions are SBCS data, mixed data, or Unicode data, then the result is obtained by comparing weighted values. The weighted values are derived by applying the collating sequence to the sort-key-expressions.

The function is applied to the set of values derived from the argument values by elimination of null values.

The data type of the result is XML. The result can be null. If the function is applied to an empty set, the result is the null value. Otherwise, the result is an XML sequence containing an item for each value in the set.

Example

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