Download presentation
Presentation is loading. Please wait.
1
Course materials may not be reproduced in whole or in part without the prior written permission of IBM. 5.1 © Copyright IBM Corporation 2008 DB2 9 Fundamentals (Exam 730) Classroom Resources Part 7: Introducing XQuery
2
© Copyright IBM Corporation 2008 Unit objectives After completing this unit, you should be able to: List fundamental XQuery concepts Write simple XQueries using several common expressions
3
© Copyright IBM Corporation 2008 Certification Exam (730) objectives Knowledge of XML data implications (non-shredding) Given an XQuery statement, knowledge to identify results
4
© Copyright IBM Corporation 2008 Sample XML document
5
© Copyright IBM Corporation 2008 XQuery navigation Navigate to the city element /Client/Address/city More path expressions: //* //email /Client/email[1]/text() /Client/Address/* /Client/data(@id) /Client/Address[state="CA"]/../email
6
© Copyright IBM Corporation 2008 Sample data for the clients table INSERT INTO clients VALUES (3227, 'Ella Kimpton', 'Gold', ' 5401 Julio Ave. San Jose CA 95116 4084630000 4081111111 4082222222 4087776666 love2shop@yahoo.com ' );
7
© Copyright IBM Corporation 2008 Simple XML data retrieval Simple XQuery to return customer contact data XQUERY db2-fn:xmlcolumn('CLIENTS.CONTACTINFO') Output from the query: 5401 Julio Ave. San Jose CA 95116 4084630000 4081111111 4082222222 4087776666 love2shop@yahoo.com
8
© Copyright IBM Corporation 2008 Specifying a single filtering predicate FLWOR expression with a new WHERE clause XQUERY FOR $y IN db2-fn:xmlcolumn('CLIENTS.CONTACTINFO') /Client/Address WHERE $y/zip="95116" RETURN $y Output from the query: 5401 Julio Ave. San Jose CA 95116
9
© Copyright IBM Corporation 2008 Converting XML to HTML Querying DB2 XML data and returning results as HTML: XQUERY { FOR $y IN db2-fn:xmlcolumn('CLIENTS.CONTACTINFO') /Client/Address ORDER BY $y/zip RETURN {$y} } HTML output of the query: 9407 Los Gatos Blvd. Los Gatos CA 95032 4209 El Camino Real Mountain View CA 95033...
10
© Copyright IBM Corporation 2008 Conditional logic XQuery with a three-part conditional expression FOR $y IN db2-fn:xmlcolumn('CLIENTS.CONTACTINFO')/Client RETURN ( IF ($y/email) THEN $y/email[1] ELSE IF ($y/phone/home) THEN {$y/phone/home/text()} ELSE $y/Address) Query output: love2shop@yahoo.com 1204 Meridian Ave. 4A San Jose CA 95124 4083332222...
11
© Copyright IBM Corporation 2008 Hybrid queries Embedding SQL within an XQuery XQUERY FOR $y IN db2-fn:sqlquery ('SELECT contactinfo FROM clients WHERE status=''Gold'' ')/Client WHERE $y/Address/city="San Jose" RETURN ( IF ($y/email) THEN {$y/email} ELSE $y/Address ) Query output love2shop@yahoo.com 1204 Meridian Ave. 4A San Jose CA 95124
12
© Copyright IBM Corporation 2008 Unit summary Having completed this unit, you should be able to: List fundamental XQuery concepts Write simple XQueries using several common expressions
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.