for and let clauses in the same expression
When a FLWOR expression contains for and let clauses, the variable bindings for the let clauses are added to the variable bindings for the for clauses.
In the following example, the for clause
includes a variable called
$a and an expression that
constructs the sequence (1, 2, 3). The let clause
includes a variable called $b and an expression that
constructs the sequence (4, 5, 6):SELECT XMLQUERY(
'for $a in (1, 2, 3)
let $b := (4, 5, 6)
return <output>{$a, $b}</output>')
FROM SYSIBM.SYSDUMMY1The for and let clauses
in this example result in three tuples of bindings. The number of
tuples is determined by the for clause. ($a = 1, $b = 4 5 6)
($a = 2, $b = 4 5 6)
($a = 3, $b = 4 5 6)The return clause
in the example executes once for each tuple of bindings. The SELECT
statement results in the following output:
<output>1 4 5 6</output><output>2 4 5 6</output><output>3 4 5 6</output>