17.10 - Example: Using XMLELEMENT to Construct an XML Element Node - Advanced SQL Engine - Teradata Database

Teradata Vantageā„¢ - XML Data Type

Product
Advanced SQL Engine
Teradata Database
Release Number
17.10
Release Date
July 2021
Content Type
Programming Reference
Publication ID
B035-1140-171K
Language
English (United States)

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>