Examples | Using XQuery/XPath Query | Teradata Vantage - Example: XQuery/XPath Query Returns the First Customer Child - Advanced SQL Engine - Teradata Database

XML Data Type

Product
Advanced SQL Engine
Teradata Database
Release Number
17.05
17.00
Published
June 2020
Language
English (United States)
Last Update
2021-01-22
dita:mapPath
amr1556233250442.ditamap
dita:ditavalPath
lze1555437562152.ditaval
dita:id
B035-1140
lifecycle
previous
Product Category
Teradata Vantageā„¢
The following query returns the first customer child of the customers document element:
SELECT xmldoc.xmlextract('/customers/customer[1]', NULL)
AS firstcustomer
FROM xmltab;
The following shows the wire-format of the XML value that is the result of this query. The single element node when serialized is a well-formed XML document.
<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>