DB2 10.5 for Linux, UNIX, and Windows

Introduction to querying XML data with SQL

XML data can be queried using an SQL fullselect or with the SQL/XML query functions of XMLQUERY and XMLTABLE. The XMLEXISTS predicate can also be used in SQL queries on XML data.

When querying XML data using only SQL, without any XQuery, you can query only at the column level by issuing a fullselect. For this reason, only entire XML documents can be returned from the query; it is not possible to return fragments of a document using only SQL.

To query within XML documents, you need to use XQuery. XQuery can be invoked from SQL using any of the following SQL/XML functions or predicate:
XMLQUERY
An SQL scalar function that returns the result of an XQuery expression as an XML sequence.
XMLTABLE
An SQL table function that returns the result of an XQuery expression as a table.
XMLEXISTS
An SQL predicate that determines whether an XQuery expression returns a non-empty sequence.