Example: Using XMLELEMENT to Construct an XML Element Node

Teradata Vantageā„¢ XML Data Type

brand
Software
Teradata Vantage
prodname
Teradata Database
Teradata Vantage NewSQL Engine
vrm_release
16.20
category
Programming Reference
featnum
B035-1140-162K

This query returns an XML element that has a serialization of <Item ID="001"/>:

SELECT XMLELEMENT(NAME Item, XMLATTRIBUTES('001' AS ID));

The result of the query is:

XMLELEMENT(NAME Item, XMLATTRIBUTES('001' AS ID) RETURNING SEQUENCE)
--------------------------------------------------------------------
<Item ID="001"></Item>

This query returns an XML element that has a serialization of <Item xmlns="http://example.teradata.com" ID="001"/>:

SELECT XMLELEMENT(NAME Item, XMLNAMESPACES(DEFAULT 'http://example.teradata.com'),
   XMLATTRIBUTES('001' AS ID));

The result of the query is:

XMLELEMENT(NAME Item, XMLNAMESPACES(DEFAULT 'http://example.teradata.com'),
XMLATTRIBUTES('001' AS ID) RETURNING SEQUENCE)
---------------------------------------------------------------------------
<Item ID="001" xmlns="http://example.teradata.com"></Item>