XMLCONCAT
The XMLCONCAT function returns a sequence containing the concatenation of a variable number of XML input arguments.
- XML-expression
- An expression that returns an XML value.
The result of the function is an XML sequence that contains the concatenation of the non-null input XML values. Null values in the input are ignored.
The result of the function is XML. The result can be null; if the result of every input value is null, the result is the null value.
Examples
Note: XMLCONCAT does not insert blank
spaces or new line characters in the output. All example output has
been formatted to enhance readability.
- Concatenate first name and last name elements by
using "first" and "last" element names for each employee
The result of the query would look similar to the following result:SELECT XMLSERIALIZE( XMLCONCAT( XMLELEMENT(NAME "first", e.firstnme), XMLELEMENT(NAME "last", e.lastname) ) AS VARCHAR(100) ) AS "result" FROM EMPLOYEE E WHERE e.lastname = 'SMITH'
result ---------------------------------------- <first>DANIEL</first><last>SMITH</last> <first>PHILIP</first><last>SMITH</last>
- Construct a department element for departments A00 and B01 containing
a list of employees sorted by first name. Include an introductory
comment immediately preceding the department element.
SELECT XMLCONCAT( XMLCOMMENT ( 'Confirm these employees are on track for their product schedule'), XMLELEMENT( NAME "Department", XMLATTRIBUTES( E.WORKDEPT AS "name"), XMLAGG( XMLELEMENT(NAME "emp", E.FIRSTNME) ORDER BY E.FIRSTNME) )) FROM EMPLOYEE E WHERE E.WORKDEPT IN ('A00', 'B01') GROUP BY E.WORKDEPT
This query produces the following result:
<!--Confirm these employees are on track for their product schedule--> <Department name="A00"> <emp>CHRISTINE</emp> <emp>SEAN</emp> <emp>VINCENZO</emp> </Department> <!--Confirm these employees are on track for their product schedule--> <Department name="B01"> <emp>MICHAEL</emp> </Department>