FOR_XML_UDF (OBJECT, VARCHAR)

Definition

This user-defined function (UDF) converts an object to XML.

FOR_XML_UDF(OBJ OBJECT, ELEMENT_NAME VARCHAR)

Parameters

OBJ OBJECT

Object to be converted.

ELEMENT_NAME VARCHAR

Element name to be given the object.

Returns

Returns a varchar in the format of XML.

Usage example

Input:

SELECT
FOR_XML_UDF(OBJECT_CONSTRUCT('id', 1, 'name', 'David'), 'employee');

Output:

<employee type="OBJECT">
    <id type="INTEGER">1</id>
    <name type="VARCHAR">David</name>
</employee>

Last updated