Integrating XQuery and SQL: Querying XML Datatypes

Once the XML data is safely stored in a relational table, the easiest way to get at the data is to use SQL to query the table and retrieve the XML-typed column, as in the following example:

SELECT CustomerName, OrderForm
FROM Customers
WHERE CustomerID = 1

However, SQL per se cannot query information inside an XML datatype instance. That is where XQuery comes in. XQuery allows us to query and transform the XML data. What we need to understand now is how to integrate the two, so that we can invoke XQuery functionality from SQL, and also provide information from the relational environment to the XQuery context.

This section introduces three ways to query XML datatype instances in the context ...

Get XQuery from the Experts: A Guide to the W3C XML Query Language now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.