Databases Reference
In-Depth Information
Example 2-13 shows a simple FLWOR expression, which selects the five star
(rating is “*****”) movie's name.
Example 2-13 Using FLWOR expression
xquery for $i in db2-fn:xmlcolumn("MOVIES.INFO")/movie/heading where
$i/rating="*****" return $i/title @
You can nest the for and let clauses of the FLWOR expression to any level. The
nesting of these clauses lets us combine different parts of the XML value.
Example 2-14 shows the nesting of these clauses in conjunction with the
constructors. The query selects the movies based on their MPAA rating,
MPAArating .
Example 2-14 Nesting FLOWOR expression
xquery for $ratings in
fn:distinct-values(db2-fn:xmlcolumn("MOVIES.INFO")/movie/movie-details/
MPAArating)
let $title:=db2-fn:xmlcolumn("MOVIES.INFO")/movie[movie-details/
MPAArating=$ratings]/heading/title
return <rating type='{$ratings}'>
{$title}
</rating>
Tip: When nesting the for and let clauses, keep in mind that the for clause
creates one binding for each XML value in the sequence, and the let clause
creates only one binding for the full sequence.
Use the order by clause to order the tuples based on the path expression. These
ordered tuples are then processed by the return clause.
Example 2-15 gives an example of the order by clause. The query selects the
movie name with the production studio order by the rating and the year of
production.
Example 2-15 Using order by clause
xquery for $i in db2-fn:xmlcolumn("MOVIES.INFO")/movie order by
$i/movie-details/year
return
<movie>
{$i/heading/title}
{$i/movie-details/production/studio}
</movie>;
Search WWH ::




Custom Search