DB2 Aggregate functions - XMLGROUP
The XMLGROUP function returns an XML value with a single XQuery document node containing one top-level element node. This is an aggregate expression that will return a single-rooted XML document from a group of rows where each row is mapped to a row subelement.
The schema is SYSIBM. The function name cannot be specified as a qualified name.
The default behavior defines a simple mapping between a result set and an XML value. Some additional notes about function behavior apply:
The provided examples are based on the following table, T1, with integer columns C1 and C2 that contain numeric data stored in a relational format.
C1 C2 ----------- ----------- 1 2 - 2 1 - - - 4 record(s) selected.
SELECT XMLGROUP(C1, C2) FROM T1
<rowset> <row> <C1>1</C1> <C2>2</C2> </row> <row> <C2>2</C2> </row> <row> <C1>1</C1> </row> </rowset> 1 record(s) selected.
SELECT XMLGROUP(C1, C2 OPTION AS ATTRIBUTES) FROM T1
<rowset> <row C1="1" C2="2"/> <row C2="2"/> <row C1="1"/> </rowset> 1 record(s) selected.
SELECT XMLGROUP( C1 AS "column1", C2 AS "column2" ORDER BY C1 OPTION ROW "entry" ROOT "document") FROM T1
<document> <entry> <column1>1</column1> <column2>2</column2> </entry> <entry> <column1>1</column1> </entry> <entry> <column2>2</column2> </entry> </document>