Example: XQuery/XPath Query Returns a Sequence of Customer Elements - Teradata Vantage

Teradata® VantageCloud Lake

Deployment
VantageCloud
Edition
Lake
Product
Teradata Vantage
Published
January 2023
ft:locale
en-US
ft:lastEdition
2024-12-11
dita:mapPath
phg1621910019905.ditamap
dita:ditavalPath
pny1626732985837.ditaval
dita:id
phg1621910019905

The following query returns a sequence of customer elements:

SELECT CAST(xmldoc.xmlextract('/customers/customer', NULL) AS VARCHAR(1024))
AS customerlist
FROM xmltab;

The return value for this query is of VARCHAR type containing the following string (serialization of a sequence is the serialization of the items of the sequence separated by a single white space character):

<customer>
   <Name>John Hancock</Name>
   <Address>100 1st Street One City, CA 12345</Address>
   <Phone1>(999)9999-999</Phone1>
   <Phone2>(999)9999-998</Phone2>
   <Fax>(999)9999-997</Fax>
   <Email>John@somecompany.com</Email>
   <order Number="NW-01-16366" Date="Feb/28/2001">
      <Contact>Mary Shannon</Contact>
      <Phone>(987)6543-210</Phone>
      <ShipTo>Widgets Inc., 123 Regency Parkway, Portland, OR 43211</ShipTo>
      <SubTotal>2355.00</SubTotal>
      <Tax>141.50</Tax>
      <Total>2496.50</Total>
      <item ID="001">
         <Quantity>100</Quantity>
         <PartNumber>F54709</PartNumber>
         <Description/>
         <UnitPrice>23.55</UnitPrice>
         <Price>2355.00</Price>
      </item>
   </order>
</customer>
<customer>
   <Name>Jim Smith</Name>
   <Address>200 2nd Street, San Diego, CA 12345</Address>
   <Phone1>(858)555-1234</Phone1>
   <Phone2>(858)555-1234</Phone2>
   <Fax>(858)555-9876</Fax>
   <Email>Jim@somecompany.com</Email>
   <order Number="JS-01-16366" Date="Feb/29/2001">
      <Contact>Jim Smith</Contact>
      <Phone>(858)555-1234</Phone>
      <ShipTo>Acme co., 2467 Pioneer Road, San Diego, CA 12345</ShipTo>
      <SubTotal>1242.00</SubTotal>
      <Tax>141.50</Tax>
      <Total>1383.50</Total>
      <item ID="001">
         <Quantity>10</Quantity>
         <PartNumber>F54709</PartNumber>
         <Description/>
         <UnitPrice>124.20</UnitPrice>
         <Price>1242.00</Price>
      </item>
   </order>
</customer>