Databases Reference
In-Depth Information
So the default axis is the child axis. The attribute axis can be represented by the
at sign (@). Similarly, the descendant axis can be represented by two forward
slashes (//).
You can filter the values selected by the path in the Query by a condition in the
same way we filter the value using the WHERE clause of the SELECT
statement. You do this by using the predicate in XQuery. Let us select all the
US-based movies from our movies database. Example 2-11 gives you the query
to get the required result.
Example 2-11 Predicate in XQuery
xquery
db2-fn:xmlcolumn('MOVIES.INFO')/movie[movie-details/country='US']/headi
ng/title
The predicate in an XPath starts with a bracket ([) and ends with the closing
bracket (]). A predicate is evaluated for the given condition and returns true if it
satisfies the condition. The nodes for which the predicate returns true are
returned as a result of the current step. The predicate can start from the root
node or from the relative path with respect to the current node. Putting (/) at the
start of the predicate makes it start from the root node. A predicate can go up to
any level in the XML value using the paths and return back to the original node
after evaluating the condition. The following comparison expressions are
supported in the predicate:
Value comparison (ne, eq, gt, ge, lt, le)
These operators are used to compare the values of the same data types. For
example:
A ne B
A and B should be of the same data type.
General comparison (!=, =, >, <, <=, >=)
These operators are used to compare the sequence. If any of the sequence
members satisfy the operator with the corresponding value in the other
sequence, the operator returns true :
- (1,2)=(2,3) returns true .
- (1,2)=(3,4) returns false .
Similarly:
- (1,2)!=(2,3) returns true because at least one set is satisfying the
operator.
- (1,1)!=(1,1) returns false .
Apart from these, you can use the logical operators AND and OR.
Search WWH ::




Custom Search