16.20 - Example: Using XMLELEMENT to Construct an XML Element Node - Teradata Database - Teradata Vantage NewSQL Engine

Teradata Vantageā„¢ XML Data Type

Product
Teradata Database
Teradata Vantage NewSQL Engine
Release Number
16.20
Release Date
March 2019
Content Type
Programming Reference
Publication ID
B035-1140-162K
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>