Databases Reference
In-Depth Information
Example 2-8 gives the example for an xmlcolumn applied on the info column of
the movie table.
Example 2-8 xmlcolumn applied on info column of the movie table
xquery db2-fn:xmlcolumn('MOVIES.INFO')
Tip: DB2 is case insensitive and treats all the table and column names in
capital letters while XML and XQuery are case sensitive. The resource
functions previously discussed are XQuery interface functions so all the table
names and column names should be passed to these functions using capital
characters or letters. Passing the object names in lower case letters can result
in an undefined object name error.
sqlquery
Instead of querying all the XML values in an XML column (as in the case of
xmlcolumn functions), we can only query a set of XML values based on a
condition in a SELECT statement using the sqlquery function, for example,
querying only the information regarding the movie with ID value 123 . For this
purpose, the sqlquery function provides you with the option to give the SQL full
select as an input to the function instead of just the column name. If you give the
full select as an input to this function, you should select XML values only. The
function returns the concatenation of all the values selected by the full select.
Example 2-9 shows how to use the sqlquery functions to select the XML values.
Example 2-9 sqlquery
xquery db2-fn:sqlquery('select info from movies where id=123')
Tip: xmlcolumn and sqlquery are xquery interface functions and are case
sensitive. Trying to use these functions in upper case letters results in an
error.
Writing XQuery
The XQuery language queries the XML data. XQuery works on a sequence of
XML documents generated by either using the resource functions.constructor
function or created as an intermediate result of another XQuery. Use XQuery,
along with SQL/XML functions, to query the XML documents stored in the DB2 9
database.
Search WWH ::




Custom Search