17.10 - Example: XQuery/XPath Query Returns Multiple Atomic Values Cast to the DECIMAL Data Type - 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)
The following query returns multiple atomic values cast to the DECIMAL data type:
SELECT CAST(x.item AS DECIMAL(16,0))
FROM xmltab,
XMLTABLE(
   'for $cust in /customers/customer return sum(order/total)'
   passing xmltab.xmldoc as "cust"
   COLUMNS "item" XML PATH ".") x;
An alternative way to write this query is as follows:
SELECT x.item
FROM xmltab,
XMLTABLE(
   'for $cust in /customers/customer return sum(order/total)'
   passing xmltab.xmldoc as "cust"
   COLUMNS "item" DECIMAL(16,0) PATH ".") x;

Both queries return the same results: each row returned will contain a single DECIMAL value.

Row #1:
   2496.50
Row #2:
   1383.50