16.10.2015 Views

Getting Started with DB2 Express-C

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

280 <strong>Getting</strong> <strong>Started</strong> <strong>with</strong> <strong>DB2</strong> <strong>Express</strong>-C<br />

xquery<br />

{<br />

for $y in db2-fn:xmlcolumn(‘CLIENTS.CONTACT’)/Client/Address<br />

order by $y/zip<br />

return {$y}<br />

}<br />

<br />

Listing 15.17 - XQuery statement <strong>with</strong> the FLWOR expression returning HTML<br />

The sample HTML returned would look as shown in Listing 15.18.<br />

<br />

<br />

<br />

9407 Los Gatos Blvd.<br />

Los Gatos<br />

ca<br />

95302<br />

<br />

<br />

<br />

4209 El Camino Real<br />

Mountain View<br />

CA<br />

95302<br />

<br />

<br />

...<br />

<br />

Listing 15.18 - Output of the query ran in Listing 15.17<br />

Example 4<br />

The following example shows how to embed SQL <strong>with</strong>in XQuery by using the db2-<br />

fn:sqlquery function. The db2-fn:sqlquery function executes an SQL query and<br />

returns only the selected XML data. The SQL query passed to db2-fn:sqlquery must<br />

only return XML data. This XML data can then be further processed by XQuery. This is<br />

illustrated in Listing 15.19.<br />

xquery<br />

for $y in<br />

db2-fn:sqlquery(<br />

‘select comments from items where srp > 100’<br />

)/Comments/Comment

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!