DB2 10.5 for Linux, UNIX, and Windows

XMLQUERY function overview

Use the XMLQUERY SQL scalar function to execute an XQuery expression from within an SQL context. You can pass variables to the XQuery expression specified in XMLQUERY. XMLQUERY returns an XML value, which is an XML sequence. This sequence can be empty or contain one or more items.

By executing XQuery expressions from within the SQL context, you can:
  • operate on parts of stored XML documents, instead of entire XML documents (only XQuery can query within an XML document; SQL alone queries at the whole document level)
  • enable XML data to participate in SQL queries
  • operate on both relational and XML data
  • apply further SQL processing to the returned XML values (for example, ordering results with the ORDER BY clause of a subselect)

Refer to the documentation on the comparison of querying methods for more details.

Note that XQuery is case-sensitive, so the XQuery expressions and variables specified in XMLQUERY must be carefully specified.

For cases where the full functionality for passing SQL expressions is not needed, a simpler syntax for passing column names without having to specify the names in the passing clause explicitly is aso available. See Simple column name passing with XMLEXISTS, XMLQUERY, and XMLTABLE.