The body of an XQuery query specifies an XQuery expression that determines the results of the XQuery query.
XQuery-query-body ::= XQuery-expression |
XQuery expressions are constructed as combinations of the expressions listed in the following table.
Table 1-65 Expressions that can be included in an XQuery expression
No. | Expression | Explanation |
---|---|---|
1 | XQuery sequence concatenation expression | Expression that concatenates XQuery sequences. |
2 | FLWOR expression |
|
3 | XQuery quantified expression | Expression that determines whether any (some) or all (every) of the XQuery items making up the specified XQuery sequence satisfy the specified criteria. |
4 | XQuery conditional expression | Expression that selects an XQuery expression depending on the result of the specified criteria and then evaluates the selected XQuery expression. |
5 | XQuery logical expression | Expression that performs logical operations (OR, AND). |
6 | XQuery comparison expression | Expression that performs a comparison. Comparisons include value comparisons, general comparisons, and node comparisons. |
7 | XQuery range expression | Expression that generates an XQuery sequence of consecutive integer (xs:int type) atomic values. |
8 | XQuery arithmetic expression | Expression that performs addition, subtraction, multiplication, division, or modulo calculation. |
9 | XQuery sequence operation expression | Expression for obtaining the union, intersection or difference for an XQuery sequence consisting of nodes. |
10 | XQuery unary expression | Expression that performs a unary operation. |
11 | XQuery value expression | Expression that specifies a value. |
12 | XQuery path expression | Expression that traverses an XQuery data model tree and selects specific nodes. |
13 | XQuery primary expression | The basic components, listed below, that constitute an XQuery path expression:
|
Concatenates XQuery sequences.
When concatenating multiple XQuery sequences, the XQuery sequences to be concatenated are evaluated from left to right and each XQuery item in the XQuery sequences is added to the end of the resulting XQuery sequence. The resulting concatenated XQuery sequence includes all the XQuery items in the XQuery sequences being concatenated. The number of XQuery items contained in the resulting concatenated XQuery sequence will be equal to the number of XQuery items in the XQuery sequence being concatenated.
XQuery-sequence-concatenation-expression ::= XQuery-single-expression [, XQuery-single-expression]... |
The following is an example of an XQuery sequence concatenation expression.
No. | Example | Result | Explanation |
---|---|---|---|
1 | 1, 2, 3, 4, 5 | (1, 2, 3, 4, 5) | Returns an XQuery sequence that is the concatenation of five XQuery sequences consisting of single atomic values of type xs:int, resulting from the evaluation of the XQuery integer literals from 1 to 5. |
2 | (1, 2, 3), (), (4, 5) | (1, 2, 3, 4, 5) | Returns an XQuery sequence that is the concatenation of the XQuery sequence consisting of the atomic values 1, 2, and 3 of type xs:int, an empty XQuery sequence, and an XQuery sequence consisting of the atomic values 4 and 5 of type xs:int. The evaluation results are the same as for the XQuery expression 1, 2, 3, 4, 5. |
Binds an XQuery variable to an XQuery sequence, evaluates an XQuery expression containing that XQuery variable, and then returns the resulting XQuery sequence.
The methods for binding an XQuery variable and evaluating the XQuery expression are as follows.
In the W3C standard, the FLWOR expressions include the FOR clause, LET clause, WHERE clause, ORDER BY clause, and RETURN clause, but HiRDB supports only the FOR clause, LET clause, and RETURN clause.
FLWOR-expression ::= {FOR-clause|LET-clause }[{FOR-clause|LET-clause }]... |
Any combination of one or more FOR or LET clauses can be specified.
If multiple FOR and LET clauses are specified, each clause is treated as nested.
Example:
XQuery expression 1 and XQuery expression 2 below have the same contents:
for $XQuery-variable-name-1 in XQuery-single- expression-1
let $XQuery-variable-name-2 := XQuery-single- expression-2
for $XQuery-variable-name-3 in XQuery-single- expression-3
let $XQuery-variable-name-4 := XQuery-single- expression-4
return XQuery-single-expression-5
for $XQuery-variable-name-1 in XQuery-single- expression-1
return
let $XQuery-variable-name-2 := XQuery-single- expression-2
return
for $XQuery-variable-name-3 in XQuery-single- expression-3
return
let $XQuery-variable-name-4 := XQuery-single- expression-4
return XQuery-single-expression-5
The evaluation of the RETURN clause is repeated as described below:
for $XQuery-variable-name-1 in XQuery-single- expression-1,
$XQuery-variable-name-2 in XQuery-single- expression-2
return XQuery-single- expression-3
for $XQuery-variable-name-1 in XQuery-single- expression-1
return for $XQuery-variable-name-2 in XQuery-single- expression-2
return XQuery-single- expression-3
Associates the result of the evaluation of XQuery-single-expression with an XQuery variable and then evaluates the RETURN clause.
The following is an example of a FLWOR expression.
<bookinfo book_id="452469630"> |
No. | Example | Result | Explanation |
---|---|---|---|
1 | for $a in $book/author return fn:string($a) | ("Jeff Jones","Bob Adams") | Applies the fn:string function to every author element node that is a child of the bookinfo element node and returns the results expressed as character strings. |
2 | for $i in (10, 20), $j in (1,2) return ($i + $j) | (11, 12, 21, 22) | Returns the same result as for $I in (10, 20) return for $j in (1, 2) return ( $i + $j ) |
3 | let $a := $book/author return $a/fn:string() | ("Jeff Jones","Bob Adams") | Applies the fn:string function to every author element node that is a child of the bookinfo element node and returns the results expressed as character strings. |
4 | for $i in (1,2) let $a := $book/author[$i] return fn:string($a) | ("Jeff Jones","Bob Adams") | Applies the fn:string function to the first and second element nodes of the author element nodes that are children of the bookinfo element node and returns the results expressed as character strings. |
5 | let $a := $book/author for $i in (1,2) return fn:string($a[$i]) | ("Jeff Jones","Bob Adams") | Applies the fn:string function to the first and second element nodes of the author element nodes that are children of the bookinfo element node and returns the results expressed as character strings. |
6 | for $a in $book/author return fn:count($a) | (1,1) | Returns the XQuery sequence that is the concatenation of the results of applying the fn:count function to every author element node that is a child of the bookinfo element node. |
7 | let $a := $book/author return fn:count($a) | (2) | Returns the result of applying the fn:count function to the XQuery sequence consisting of the author element nodes that are the children of the bookinfo element node. |
Determines whether any (some) or all (every) of the XQuery items making up the specified XQuery sequence satisfy the specified criteria, and returns the result.
XQuery-quantified-expression::= {some|every} $ XQuery-variable-name in XQuery-single-expression |
The following is an example of an XQuery quantified expression.
Element represented by the XQuery variable book:
<bookinfo book_id="452469630"> |
XQuery quantified expression examples and results:
No. | Example | Result | Explanation |
---|---|---|---|
1 | some $text in $book /author/text() satisfies ( $text eq "Bob Adams" ) | TRUE | TRUE, because a text node of an author element node which is a child of the bookinfo element node has contents equal to Bob Adams. |
2 | some $i in (1, 2, 3), $j in (4, 5, 6) satisfies $i + $j >= 6 | TRUE | Result of this XQuery quantified expression is TRUE because some was specified and there are combinations of XQuery items (example: $i = 1, $j = 5) such that $i + $j >= 6. |
3 | every $i in (1, 2, 3), $j in (4, 5, 6) satisfies $i + $j >= 6 | FALSE | Result of this XQuery quantified expression is FALSE because every was specified and there are combinations of XQuery items (example: $i = 1, $j = 4) that do not satisfy $i + $j >= 6. |
Selects an XQuery expression depending on the result of the specified criteria and then returns the result of evaluating the selected XQuery expression.
XQuery-conditional-expression ::= if ( XQuery-expression ) then XQuery-single-expression else XQuery-single-expression |
The following is an example of an XQuery conditional expression.
XML element represented by the XQuery variable book1:
<bookinfo book_id="452469630"> |
XML element represented by the XQuery variable book2:
<bookinfo book_id="452469631"> |
XQuery conditional expression examples and results:
No. | Example | Result | Explanation |
---|---|---|---|
1 | if ($book1/price > $book2/price) then $book1 else $book2 | The element node indicated in the XQuery variable book1 specified in the then clause | Because the typed-value (=30.00) of the price element node that is the child of the element node indicated in $book1 is greater than the typed-value (=25.00) of the price element node that is the child of the element node indicated in $book2, the element node indicated in $book1 is returned. |
Returns the result of performing a logical operation (OR, AND) on XQuery comparison expressions.
Under certain conditions, the evaluation result from the XQuery comparison expression is returned unchanged.
XQuery-logical-expression ::= XQuery-OR-expression |
If the or operator is specified, the OR logical operation is performed on the results of evaluating XQuery AND expressions.
If you specify the XQuery AND expression by itself, the evaluation result from that XQuery AND expression is returned unchanged.
When the OR logical operation is performed, if the result of evaluating each XQuery AND expression is not a single XQuery sequence with a Boolean value (atomic value of the xs:boolean type), the OR logical operation is performed after implicitly converting the expression to a single XQuery sequence with a Boolean value (atomic value of the xs:boolean type).
The following table indicates the results of the OR operation based on the Boolean values of the first operand and second operand.
Table 1-66 Result of the OR logical operation in an XQuery logical expression
No. | First operand | Second operand | |
---|---|---|---|
TRUE | FALSE | ||
1 | TRUE | TRUE | TRUE |
2 | FALSE | TRUE | FALSE |
If the and operator is specified, the AND logical operation is performed on the results of evaluating XQuery comparison expressions.
If you specify the XQuery comparison expression by itself, the evaluation result from that XQuery comparison expression is returned unchanged.
When the AND logical operation is performed, if the result of evaluating each XQuery comparison expression is not a single XQuery sequence with a Boolean value (atomic value of the xs:boolean type), the AND logical operation is performed after implicitly converting the expression to a single XQuery sequence with a Boolean value (atomic value of the xs:boolean type).
The following table indicates the results of the AND operation based on the Boolean values of the first operand and second operand.
Table 1-67 Result of the AND logical operation in an XQuery logical expression
No. | First operand | Second operand | |
---|---|---|---|
TRUE | FALSE | ||
1 | TRUE | TRUE | FALSE |
2 | FALSE | FALSE | FALSE |
Returns the result of a comparison to an XQuery range expression.
Under certain conditions, the evaluation result from the XQuery range expression is returned unchanged.
XQuery-comparison-expression ::= XQuery-range-expression [{value-comparison| general-comparison| node-comparison} XQuery-range-expression] |
If you specify a value comparison, general comparison or node comparison, the results of evaluating the XQuery range expressions are returned.
If you specify the XQuery range expression by itself, the evaluation result from that XQuery range expression is returned unchanged.
Compares single atomic values to each other.
The following table describes each of the value comparison functions.
Table 1-68 Value comparison methods
No. | Value comparison operator | Conditions which evaluate to TRUE |
---|---|---|
1 | eq | The values of the first comparison term and the second comparison term are equal. |
2 | ne | The values of the first comparison term and the second comparison term are not equal. |
3 | lt | The value of the first comparison term is less than the value of the second comparison term. |
4 | le | The value of the first comparison term is less than or equal to the value of the second comparison term. |
5 | gt | The value of the first comparison term is greater than the value of the second comparison term. |
6 | ge | The value of the first comparison term is greater than or equal to the value of the second comparison term. |
Comparisons are performed in the following order:
An error results if the XQuery data types of the comparison terms cannot be compared. The following table indicates which combinations of XQuery data types can be compared.
Table 1-69 Combinations of XQuery data types that can be compared
XQuery data type of the first operand | XQuery data type of the second operand | ||||||
---|---|---|---|---|---|---|---|
xs:string | Numeric data type | xs:dateTime | xs:date | xs:time | xs:hexBinary | s:boolean | |
xs:string | Y | N | N | N | N | N | N |
Numeric data type | N | Y | N | N | N | N | N |
xs:dateTime | N | N | Y | N | N | N | N |
xs:date | N | N | N | Y | N | N | N |
xs:time | N | N | N | N | Y | N | N |
xs:hexBinary | N | N | N | N | N | Y# | N |
xs:boolean | N | N | N | N | N | N | Y# |
The following tables list the results of comparing xs:double types with each operator.
Table 1-70 Results of comparing xs:double types (eq operator)
No. | First operand (value converted to xs:double type) | Second operand (value converted to xs:double type) | ||||||
---|---|---|---|---|---|---|---|---|
+0 | -0 | +INF | -INF | NaN | Other negative numbers | All others | ||
1 | +0 | TRUE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE |
2 | -0 | TRUE | TRUE | FALSE | FALSE | FALSE | FALSE | FALSE |
3 | +INF | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE |
4 | -INF | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE |
5 | NaN | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
6 | Other negative numbers | FALSE | FALSE | FALSE | FALSE | FALSE | Comparison result | Comparison result |
7 | All others | FALSE | FALSE | FALSE | FALSE | FALSE | Comparison result | Comparison result |
Table 1-71 Results of comparing xs:double types (ne operator)
No. | First operand (value converted to xs:double type) | Second operand (value converted to xs:double type) | ||||||
---|---|---|---|---|---|---|---|---|
+0 | -0 | +INF | -INF | NaN | Other negative numbers | All others | ||
1 | +0 | FALSE | FALSE | TRUE | TRUE | TRUE | TRUE | TRUE |
2 | -0 | FALSE | FALSE | TRUE | TRUE | TRUE | TRUE | TRUE |
3 | +INF | TRUE | TRUE | FALSE | TRUE | TRUE | TRUE | TRUE |
4 | -INF | TRUE | TRUE | TRUE | FALSE | TRUE | TRUE | TRUE |
5 | NaN | TRUE | TRUE | TRUE | TRUE | TRUE | TRUE | TRUE |
6 | Other negative numbers | TRUE | TRUE | TRUE | TRUE | TRUE | Comparison result | Comparison result |
7 | All others | TRUE | TRUE | TRUE | TRUE | TRUE | Comparison result | Comparison result |
Table 1-72 Results of comparing xs:double types (lt operator)
No. | First operand (value converted to xs:double type) | Second operand (value converted to xs:double type) | ||||||
---|---|---|---|---|---|---|---|---|
+0 | -0 | +INF | -INF | NaN | Other negative numbers | All others | ||
1 | +0 | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | TRUE |
2 | -0 | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | TRUE |
3 | +INF | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
4 | -INF | TRUE | TRUE | TRUE | FALSE | FALSE | TRUE | TRUE |
5 | NaN | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
6 | Other negative numbers | TRUE | TRUE | TRUE | FALSE | FALSE | Comparison result | Comparison result |
7 | All others | FALSE | FALSE | TRUE | FALSE | FALSE | Comparison result | Comparison result |
Table 1-73 Results of comparing xs:double types (le operator)
No. | First operand (value converted to xs:double type) | Second operand (value converted to xs:double type) | ||||||
---|---|---|---|---|---|---|---|---|
+0 | -0 | +INF | -INF | NaN | Other negative numbers | All others | ||
1 | +0 | TRUE | TRUE | TRUE | FALSE | FALSE | FALSE | TRUE |
2 | -0 | TRUE | TRUE | TRUE | FALSE | FALSE | FALSE | TRUE |
3 | +INF | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE | FALSE |
4 | -INF | TRUE | TRUE | TRUE | TRUE | FALSE | TRUE | TRUE |
5 | NaN | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
6 | Other negative numbers | TRUE | TRUE | TRUE | FALSE | FALSE | Comparison result | Comparison result |
7 | All others | FALSE | FALSE | TRUE | FALSE | FALSE | Comparison result | Comparison result |
Table 1-74 Results of comparing xs:double types (gt operator)
No. | First operand (value converted to xs:double type) | Second operand (value converted to xs:double type) | ||||||
---|---|---|---|---|---|---|---|---|
+0 | -0 | +INF | -INF | NaN | Other negative numbers | All others | ||
1 | +0 | FALSE | FALSE | FALSE | TRUE | FALSE | TRUE | FALSE |
2 | -0 | FALSE | FALSE | FALSE | TRUE | FALSE | TRUE | FALSE |
3 | +INF | TRUE | TRUE | FALSE | TRUE | FALSE | TRUE | TRUE |
4 | -INF | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
5 | NaN | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
6 | Other negative numbers | FALSE | FALSE | FALSE | TRUE | FALSE | Comparison result | Comparison result |
7 | All others | TRUE | TRUE | FALSE | TRUE | FALSE | Comparison result | Comparison result |
Table 1-75 Results of comparing xs:double types (ge operator)
No. | First operand (value converted to xs:double type) | Second operand (value converted to xs:double type) | ||||||
---|---|---|---|---|---|---|---|---|
+0 | -0 | +INF | -INF | NaN | Other negative numbers | All others | ||
1 | +0 | TRUE | TRUE | FALSE | TRUE | FALSE | TRUE | FALSE |
2 | -0 | TRUE | TRUE | FALSE | TRUE | FALSE | TRUE | FALSE |
3 | +INF | TRUE | TRUE | TRUE | TRUE | FALSE | TRUE | TRUE |
4 | -INF | FALSE | FALSE | FALSE | TRUE | FALSE | FALSE | FALSE |
5 | NaN | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE | FALSE |
6 | Other negative numbers | FALSE | FALSE | FALSE | TRUE | FALSE | Comparison result | Comparison result |
7 | All others | TRUE | TRUE | FALSE | TRUE | FALSE | Comparison result | Comparison result |
Compares XQuery sequences of any length to each other.
Comparisons are performed in the following sequence:
Table 1-76 General comparisons and their corresponding value comparisons
No. | General comparison operator | Corresponding value comparison |
---|---|---|
1 | = | eq |
2 | !=, <> | ne |
3 | < | lt |
4 | <= | le |
5 | > | gt |
6 | >= | ge |
Table 1-77 Type conversion of atomic values of the xs:untypedAtomic type
No. | XQuery data type of the other atomic value | XQuery data type after type conversion |
---|---|---|
1 | Numeric data type | xs:double |
2 | xs:untypedAtomic | xs:string |
3 | xs:string | xs:string |
4 | Other than the above | Same XQuery data type as the other atomic value |
Compares nodes to each other based on node ID and document order.
The node ID, which is bound to all nodes in the tree representation of the XQuery data model, acts as a unique identifier within the tree.
The following table describes the ways nodes can be compared.
Table 1-78 Node comparisons
No. | Node comparison operator | Conditions under which TRUE |
---|---|---|
1 | is | The node IDs of the two nodes being compared are the same. |
2 | << | The first node being compared appears before the second node being compared in the document order. |
3 | >> | The first node being compared appears after the second node being compared in the document order. |
Comparisons are performed according to the following procedures:
The following is an example of an XQuery comparison expression.
Element represented by the XQuery variable book:
<bookinfo book_id="452469630"> |
XQuery comparison expression examples and results:
No. | Example | Result | Explanation |
---|---|---|---|
1 | $book[@book_id eq "452469630" ] | bookinfo element node | Because the typed-value of the book_id attribute node of the bookinfo element node in the XQuery variable book equals 452469630, the result is the bookinfo element node from the XQuery variable book. |
2 | (1, 2) = (2, 3) | TRUE | The result is TRUE because the eq relation holds between the second XQuery item in the first comparison term and the first XQuery item in the second comparison term. |
3 | (1, 2) != (2, 3) | TRUE | The result is TRUE because the ne relation holds between the first XQuery item in the first comparison term and the first XQuery item in the second comparison term. |
Returns an XQuery sequence consisting of atomic values that are consecutive integer values (xs:int type).
Under certain conditions, the evaluation result from the XQuery arithmetic expression is returned unchanged.
XQuery-range-expression ::= XQuery-arithmetic-expression [to XQuery-arithmetic-expression] |
If to is specified, compares the results of evaluating the XQuery arithmetic expressions.
If you specify the XQuery arithmetic expression by itself, the evaluation result from that XQuery arithmetic expression is returned unchanged.
If to is specified, the XQuery sequence generated according to the following rules is returned.
The following example shows an XQuery range expression.
No. | Example | Result | Explanation |
---|---|---|---|
1 | ( 1 to 10 ) | (1, 2, 3, 4, 5, 6, 7, 8, 9, 10) | Generates the XQuery sequence consisting of integer values from 1 to 10. |
Returns the result of addition, subtraction, multiplication, division, or modulo calculations.
Under certain conditions, the evaluation result from the XQuery sequence operation expression is returned unchanged.
XQuery-arithmetic-expression ::= XQuery-addition-or-subtraction-expression |
If an operator (+, -) is specified, the results of evaluating the XQuery multiplication or division expression are added or subtracted.
If you specify the XQuery multiplication or division expression by itself, the evaluation result from that XQuery multiplication or division expression is returned unchanged.
The following table describes the meaning and function of each operator.
Table 1-79 Functions of operators in XQuery addition or subtraction expressions
No. | Operator | Meaning | Function |
---|---|---|---|
1 | + | Addition | Add the second operand to the first operand. |
2 | - | Subtraction | Subtract the second operand from the first operand. |
If an operator (*, div, idiv, mod) is specified, multiplication, division, or modulo calculations are performed on the results of evaluating the XQuery sequence operation expressions.
If you specify the XQuery sequence operation expression by itself, the evaluation result from that XQuery sequence operation expression is returned unchanged.
The following table describes the meaning and function of each operator.
Table 1-80 Functions of operators in XQuery multiplication or division expressions
No. | Operator | Meaning | Function |
---|---|---|---|
1 | * | Multiplication | Multiply the first operand by the second operand. |
2 | div | Division | Divide the first operand by the second operand. |
3 | idiv | Integer division | Truncate the result of dividing the first operand by the second operand to an integer value. |
4 | mod | Modulo | Calculate the remainder when the first operand a is divided by the second operand b. The result of this operation is a - (a idiv b)* b. |
Addition, subtraction, multiplication, division, and modulo calculations are performed on XQuery arithmetic expressions in the following sequence:
Table 1-81 Relationship between the XQuery data types of the operands and the XQuery data type of the result (+ operator)
No. | First operand | Second operand | ||
---|---|---|---|---|
xs:int | xs:decimal | xs:double | ||
1 | xs:int | xs:int | xs:decimal | xs:double |
2 | xs:decimal | xs:decimal | xs:decimal | xs:double |
3 | xs:double | xs:double | xs:double | xs:double |
Table 1-82 Relationship between the XQuery data types of the operands and the XQuery data type of the result (- operator)
No. | First operand | Second operand | ||
---|---|---|---|---|
xs:int | xs:decimal | xs:double | ||
1 | xs:int | xs:int | xs:decimal | xs:double |
2 | xs:decimal | xs:decimal | xs:decimal | xs:double |
3 | xs:double | xs:double | xs:double | xs:double |
Table 1-83 Relationship between the XQuery data types of the operands and the XQuery data type of the result (* operator)
No. | First operand | Second operand | ||
---|---|---|---|---|
xs:int | xs:decimal | xs:double | ||
1 | xs:int | xs:int | xs:decimal | xs:double |
2 | xs:decimal | xs:decimal | xs:decimal | xs:double |
3 | xs:double | xs:double | xs:double | xs:double |
Table 1-84 Relationship between the XQuery data types of the operands and the XQuery data type of the result (div operator)
No. | First operand | Second operand | ||
---|---|---|---|---|
xs:int | xs:decimal | xs:double | ||
1 | xs:int | xs:decimal | xs:decimal | xs:double |
2 | xs:decimal | xs:decimal | xs:decimal | xs:double |
3 | xs:double | xs:double | xs:double | xs:double |
Table 1-85 Relationship between the XQuery data types of the operands and the XQuery data type of the result (idiv operator)
No. | First operand | Second operand | ||
---|---|---|---|---|
xs:int | xs:decimal | xs:double | ||
1 | xs:int | xs:int | xs:int | xs:int |
2 | xs:decimal | xs:int | xs:int | xs:int |
3 | xs:double | xs:int | xs:int | xs:int |
Table 1-86 Relationship between the XQuery data types of the operands and the XQuery data type of the result (mod operator)
No. | First operand | Second operand | ||
---|---|---|---|---|
xs:int | xs:decimal | xs:double | ||
1 | xs:int | xs:int | xs:decimal | xs:double |
2 | xs:decimal | xs:decimal | xs:decimal | xs:double |
3 | xs:double | xs:double | xs:double | xs:double |
Table 1-87 Result when at least one of the operands is xs:double type (+ operator)
No. | First operand (value converted to xs:double type) | Second operand (value converted to xs:double type) | ||||||
---|---|---|---|---|---|---|---|---|
+0 | -0 | +INF | -INF | NaN | Other negative numbers | All others | ||
1 | +0 | +0 | +0 | +INF | -INF | NaN | Result of addition | Result of addition |
2 | -0 | +0 | -0 | +INF | -INF | NaN | Result of addition | Result of addition |
3 | +INF | +INF | +INF | +INF | NaN | NaN | +INF | +INF |
4 | -INF | -INF | -INF | NaN | -INF | NaN | -INF | -INF |
5 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
6 | Other negative numbers | Result of addition | Result of addition | +INF | -INF | NaN | Result of addition | Result of addition |
7 | All others | Result of addition | Result of addition | +INF | -INF | NaN | Result of addition | Result of addition |
Table 1-88 Result when at least one of the operands is xs:double type (- operator)
No. | First operand (value converted to xs:double type) | Second operand (value converted to xs:double type) | ||||||
---|---|---|---|---|---|---|---|---|
+0 | -0 | +INF | -INF | NaN | Other negative numbers | All others | ||
1 | +0 | +0 | +0 | -INF | +INF | NaN | Result of subtraction | Result of subtraction |
2 | -0 | -0 | +0 | -INF | +INF | NaN | Result of subtraction | Result of subtraction |
3 | +INF | +INF | +INF | NaN | +INF | NaN | +INF | +INF |
4 | -INF | -INF | -INF | -INF | NaN | NaN | -INF | -INF |
5 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
6 | Other negative numbers | Result of subtraction | Result of subtraction | -INF | +INF | NaN | Result of subtraction | Result of subtraction |
7 | All others | Result of subtraction | Result of subtraction | -INF | +INF | NaN | Result of subtraction | Result of subtraction |
Table 1-89 Result when at least one of the operands is xs:double type (* operator)
No. | First operand (value converted to xs:double type) | Second operand (value converted to xs:double type) | ||||||
---|---|---|---|---|---|---|---|---|
+0 | -0 | +INF | -INF | NaN | Other negative numbers | All others | ||
1 | +0 | +0 | -0 | NaN | NaN | NaN | Result of multiplication | Result of multiplication |
2 | -0 | -0 | +0 | NaN | NaN | NaN | Result of multiplication | Result of multiplication |
3 | +INF | NaN | NaN | +INF | -INF | NaN | -INF | +INF |
4 | -INF | NaN | NaN | -INF | +INF | NaN | +INF | -INF |
5 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
6 | Other negative numbers | Result of multiplication | Result of multiplication | -INF | +INF | NaN | Result of multiplication | Result of multiplication |
7 | All others | Result of multiplication | Result of multiplication | +INF | -INF | NaN | Result of multiplication | Result of multiplication |
Table 1-90 Result when at least one of the operands is xs:double type (div operator)
No. | First operand (value converted to xs:double type) | Second operand (value converted to xs:double type) | ||||||
---|---|---|---|---|---|---|---|---|
+0 | -0 | +INF | -INF | NaN | Other negative numbers | All others | ||
1 | +0 | NaN | NaN | +0 | -0 | NaN | Result of division | Result of division |
2 | -0 | NaN | NaN | -0 | +0 | NaN | Result of division | Result of division |
3 | +INF | +INF | -INF | NaN | NaN | NaN | -INF | +INF |
4 | -INF | -INF | +INF | NaN | NaN | NaN | +INF | -INF |
5 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
6 | Other negative numbers | -INF | INF | -0 | +0 | NaN | Result of division | Result of division |
7 | All others | INF | -INF | +0 | -0 | NaN | Result of division | Result of division |
Table 1-91 Result when at least one of the operands is xs:double type (idiv operator)
No. | First operand (value converted to xs:double type) | Second operand (value converted to xs:double type) | ||||||
---|---|---|---|---|---|---|---|---|
+0 | -0 | +INF | -INF | NaN | Other negative numbers | All others | ||
1 | +0 | Divide by zero error | Divide by zero error | 0 | 0 | Type conversion error | Result of integer division | Result of integer division |
2 | -0 | Divide by zero error | Divide by zero error | 0 | 0 | Type conversion error | Result of integer division | Result of integer division |
3 | +INF | Divide by zero error | Divide by zero error | Type conversion error | Type conversion error | Type conversion error | Type conversion error | Type conversion error |
4 | -INF | Divide by zero error | Divide by zero error | Type conversion error | Type conversion error | Type conversion error | Type conversion error | Type conversion error |
5 | NaN | Divide by zero error | Divide by zero error | Type conversion error | Type conversion error | Type conversion error | Type conversion error | Type conversion error |
6 | Other negative numbers | Divide by zero error | Divide by zero error | 0 | 0 | Type conversion error | Result of integer division | Result of integer division |
7 | All others | Divide by zero error | Divide by zero error | 0 | 0 | Type conversion error | Result of integer division | Result of integer division |
Table 1-92 Result when at least one of the operands is xs:double type (mod operator)
No. | First operand (value converted to xs:double type) | Second operand (value converted to xs:double type) | ||||||
---|---|---|---|---|---|---|---|---|
+0 | -0 | +INF | -INF | NaN | Other negative numbers | All others | ||
1 | +0 | NaN | NaN | +0 | +0 | NaN | Result of modulo operation | Result of modulo operation |
2 | -0 | NaN | NaN | -0 | -0 | NaN | Result of modulo operation | Result of modulo operation |
3 | +INF | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
4 | -INF | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
5 | NaN | NaN | NaN | NaN | NaN | NaN | NaN | NaN |
6 | Other negative numbers | NaN | NaN | First operand (value converted to xs:double type) | First operand (value converted to xs:double type) | NaN | Result of modulo operation | Result of modulo operation |
7 | All others | NaN | NaN | First operand (value converted to xs:double type) | First operand (value converted to xs:double type) | NaN | Result of modulo operation | Result of modulo operation |
The subtraction operator (-) must be preceded by either a space (X'20'), TAB (X'09'), NL (X'0a') or CR (X'0d'). Without one of these characters, it is considered part of the name specified before the subtraction operator. For example, a-b is interpreted as a name, whereas a - b and a -b are interpreted as XQuery arithmetic expressions.
The following are examples of XQuery arithmetic expressions.
No. | Example | Result (XQuery data type) |
---|---|---|
1 | 4 - 2 | 2 (xs:int) |
2 | 5 div 2 | 2.5 (xs:decimal) |
3 | 5 idiv 2 | 2 (xs:int) |
4 | 5 mod 2 | 1 (xs:int) |
Treats XQuery sequences consisting of nodes as ordered sets and returns the XQuery sequence that results from performing the union, intersection, or difference operations.
Under certain conditions, the evaluation result from the XQuery unary expression is returned unchanged.
XQuery-sequence-operation-expression ::= XQuery-union-expression |
If union or a vertical bar (|) is specified, this derives an XQuery sequence consisting of all the different nodes that are contained in the two XQuery sequences that are the results of evaluating the XQuery intersection expressions or XQuery difference expressions.
If you specify the XQuery intersection expression or the XQuery difference expression by itself, the evaluation result from that XQuery intersection expression or XQuery difference expression is returned unchanged.
If intersect is specified, this derives an XQuery sequence consisting of all the different nodes that are contained in both of the two XQuery sequences that are the results of evaluating the XQuery unary expressions.
If you specify the XQuery unary expression by itself, the evaluation result from that XQuery unary expression is returned unchanged.
If except is specified, this derives an XQuery sequence consisting of all the different nodes that are contained in the XQuery sequence that is the result of evaluating the first XQuery unary expression, but that are not contained in the XQuery sequence that is the result of evaluating the second XQuery unary expression.
If you specify the XQuery unary expression by itself, the evaluation result from that XQuery unary expression is returned unchanged.
Note that the order of evaluation is different for the XQuery sequence operation expressions (union, intersect, and except) and the set operations (UNION and EXCEPT) in the body of an SQL query.
The following are examples of XQuery sequence operation expressions.
XQuery sequence operation expression examples and results:
No. | Example | Result |
---|---|---|
1 | (A,B) union (A,B) | (A, B) |
2 | (A,B) union (B,C) | (A, B, C) |
3 | (A,B) intersect (A,B) | (A, B) |
4 | (A,B) intersect (B,C) | (B) |
5 | (A,B) except (A,B) | () |
6 | (A,B) except (B,C) | (A) |
Returns the result of performing a unary operation on an XQuery value expression.
Under certain conditions, the evaluation result from the XQuery value expression is returned unchanged.
XQuery-unary-expression ::= [{-| +}]... XQuery-value-expression |
If a unary operator (-, +) is specified, the result of performing the unary operation on the XQuery value expression is returned.
If you specify the XQuery value expression by itself, the evaluation result from that XQuery value expression is returned unchanged.
The following table describes the meaning and function of each operator.
Table 1-93 Functions of operators in XQuery unary expressions
No. | Operator | Meaning | Function |
---|---|---|---|
1 | - | Minus sign | Reverses the sign. |
2 | + | Plus sign | Does not reverse the sign. |
In XQuery unary expressions, unary operations are performed the following sequence:
Returns the result of evaluating an XQuery path expression.
XQuery-value-expression ::= XQuery-path-expression |
Specify the value to be evaluated in an XQuery path expression.
Returns the result of evaluating the selected nodes in the XQuery data model.
XQuery-path-expression ::= {/[relative-path-expression]|//relative-path-expression|relative-path-expression} |
Selects a node at the root of the tree in which the context item belongs.
An error results if the context item is not a node.
Selects a node at the root of the tree node in which the context item belongs, and all of the descendant nodes of that node.
An error results if the context item is not a node.
A forward slash (/) specified other than at the beginning of an XQuery path expression is treated as a separator for a step expression. The XQuery sequence obtained by evaluating the step expressions is evaluated from left to right.
For example, the relative path expression E1/E2 is evaluated as follows:
The XQuery sequence resulting from evaluating the step expression on the left side of the forward slash cannot contain atomic values.
This is a short form of the expression /descendant-or-self::node()/.
For each context item from the results of evaluating the step expression specified on the left side, evaluates the step expression (the context item itself and its descendant nodes) specified on the right side of the XQuery sequence.
The XQuery sequence resulting from evaluating the step expression on the left side of the double forward slash cannot contain atomic values.
The axis step expression returns an XQuery sequence consisting of result nodes that have been narrowed down according to the name, kind of node, and other criteria you specify. They are obtained by traversing the specified tree starting from the context item. The nodes in this XQuery sequence become the next context items.
An error results if the context item is not a node.
The axis step returns an XQuery sequence consisting of those nodes that meet the name test or kind test out of all of the nodes that are reachable along the specified axis starting from the context item. The nodes in this XQuery sequence become the next context items.
Table 1-94 List of axes
No. | Axis | Explanation | Assigning context positions |
---|---|---|---|
1 | child:: | Indicates child nodes. | Document order |
2 | descendant:: | Indicates descendant nodes. | |
3 | attribute:: | Indicates the attribute nodes belonging to the context item node. | |
4 | self:: | Indicates the context item node itself. | |
5 | descendant-or-self | Indicates the context item node itself and all of its descendant nodes. | |
6 | following-sibling:: | Indicates the sibling nodes that follow the context item node, in document order. If the context item node is an attribute node, the result is an empty XQuery sequence. | |
7 | following:: | Indicates nodes that are not descendants of the context item node and that follow it in document order. Attribute nodes are not selected. | |
8 | parent:: | Indicates the parent node. If the context item node has no parent node, the result is an empty XQuery sequence. | |
9 | ancestor:: | Indicates the ancestor nodes. | Reverse document order |
10 | preceding-sibling:: | Indicates the sibling nodes that precede the context item node, in document order. If the context item node is an attribute node, the result is an empty XQuery sequence. | |
11 | preceding:: | Indicates nodes that are not ancestors of the context item node and that precede it in document order. Attribute nodes are not selected. | |
12 | ancestor-or-self:: | Indicates the context item node itself and all of its ancestor nodes. |
Figure 1-17 Axes
Specify that only nodes that match the specified name are to be selected from all of the nodes that can be reached by traversing the specified axis.
Specify that only nodes that match the specified kind are selected from among all of the nodes that can be reached by traversing the specified axis.
The following table lists the kind tests.
Table 1-95 List of kind tests
No. | Category | How specified | Explanation |
---|---|---|---|
1 | Document test | document-node() | Matches any document node. |
2 | document-node(element-test) | Among document nodes that have only one element node as a child node (all their other child nodes being comment nodes or processing instruction nodes only), matches any document nodes in which the child element node matches the element test. | |
3 | Element test | element() | Matches any element node. |
4 | element(*) | ||
5 | element(qualified-name) | Among XML elements, matches element nodes whose expanded qualified name is equivalent to the post-expand qualified name of the specified qualified name. | |
6 | Attribute test | attribute() | Matches any attribute node. |
7 | attribute(*) | ||
8 | attribute(qualified-name) | Among XML attributes, matches element nodes whose expanded qualified name is equivalent to the specified qualified name. | |
9 | Processing instruction test | processing-instruction() | Matches any processing instruction node. |
10 | processing-instruction(processing-instruction-target) | Among processing instruction nodes, matches processing instruction nodes with values for the processing instruction target property that match the specified processing instruction target. | |
11 | Comment test | comment() | Matches any comment node. |
12 | Text test | text() | Matches any text node. |
13 | Any kind test | node() | Matches any kind of node. |
Describes an axis step in a simplified manner.
Table 1-96 Optional axis step examples
No. | Optional axis step | Full notation with the same meaning | Meaning |
---|---|---|---|
1 | /elem/ElemName | /elem/child::ElemName | Denotes the child node ElemName from among the child nodes of the context item after the evaluation of elem. |
2 | /elem/@AttrName | /elem/attribute::AttrName | Denotes the attribute node AttrName from among the attribute nodes of the context item after the evaluation of elem. |
3 | /elem/attribute() | /elem/attribute::attribute() | Denotes all the attribute nodes of the context item after the evaluation of elem. |
4 | /elem/.. | /elem/parent::node() | Denotes the parent node of the context item after the evaluation of elem. |
Evaluates XQuery-primary-expression. If XQuery-predicate is specified, the condition in XQuery-predicate is used to narrow down the XQuery items in the XQuery sequence that is the result of evaluating XQuery-primary-expression.
The condition used to narrow down the context items is specified in XQuery expression.
The specified XQuery expression is evaluated for each context item in the XQuery predicate.
The results of evaluating the XQuery predicate are as follows:
The following is an example of an XQuery path expression.
No. | Example | Explanation |
---|---|---|
1 | child::bookinfo | Selects the bookinfo element node that is the child node of the context item. |
2 | bookinfo | Short for child::bookinfo. |
3 | attribute::book_id | Selects the book_id attribute node of the context item. |
4 | @book_id | Short for attribute::book_id. |
5 | attribute::* | Selects all the attribute nodes belonging to the context item. |
6 | parent::element() | Selects the element node whose parent node is the context item. |
7 | bookinfo[category="programming"] | Selects the bookinfo element node that has a child node with a category element node for which the value of the typed-value property is programming. |
8 | bookinfo[@book_id = "12345"] | Selects the bookinfo element node whose child node is the context item for which the value of its book_id attribute is 12345. |
9 | author[2] | Select the second author element node whose child node is the context item. |
The basic components that constitute XQuery path expressions.
XQuery primary expressions include the following:
XQuery-primary-expression ::= {XQuery-literal| XQuery-variable-reference| |
Each XQuery primary expression is described below.
Table 1-97 XQuery literals
No. | XQuery literal | Result | XQuery data type to interpret | ||
---|---|---|---|---|---|
Format | Explanation | ||||
1 | XQuery numeric literal | XQuery integer literal# | [sign]unsigned-integer Examples: -123 45 6789 | An unsigned integer is represented as a sequence of numeric characters. The sign is expressed as + or -. | xs:int |
2 | XQuery decimal literal | [sign][integer-part].[fractional-part] Examples: 12.3 -456. .789 | The integer and fractional parts are represented as unsigned integers. At least one part, either the integer part or fractional part, must be specified. | xs:decimal | |
3 | XQuery floating-point literal | mantissa{E| e}exponent Examples: 1.0E2 .5E+67 | Either an integer literal or a decimal literal as the mantissa, followed by a one- to three-digit integer literal as the exponent. The exponent represents a power of 10. | xs:double | |
4 | XQuery character string literal | {"character-string"| 'character-string'} Examples: "HiRDB" 'HITACHI' '''06.9.13' | A character string is represented as a sequence of characters. To use a double quotation mark in a string that is itself enclosed in double quotation marks, specify two consecutive double quotation marks. To use a single quotation mark in a character string, specify two consecutive single quotation marks. The following character strings are used in place of the corresponding special characters.
| xs:string |
XQuery-variable-reference ::= $ XQuery-variable-name |
/bookinfo[price> $PRICE] |
parenthesized-XQuery-expression ::= ( [XQuery-expression] ) |
No. | Example | Result | Explanation |
---|---|---|---|
1 | (2 + 4) * 5 | ( 30 ) | The 2 + 4 in parentheses is evaluated first. If the 2 + 4 were not in parentheses, the XQuery multiplication expression 4 * 5 would be evaluated first, and the result would be 22. |
context-item-expression ::= period |
No. | Example | Result | Explanation |
---|---|---|---|
1 | (1 to 20)[. mod 5 eq 0] | (5, 10, 15, 20) | First, the XQuery sequence consisting of the integer values from 1 to 20 is generated by the XQuery range expression. The XQuery predicate following the range expression is then evaluated, with each XQuery item in the generated XQuery sequence as a context item. The result is the XQuery sequence consisting of the XQuery items for which this evaluation result is TRUE. |
function-invocation ::= XQuery-function-name ( [argument [, argument]...] ) |