The variable in the outer FOR loop shows incorrect value in the inner nested FOR loop
I have the following nested loop that does not return what I am expecting to get.
SQL> select t.* from xmltable (
2 '
3 let $str := "ABCD"
4 for $i at $a in 1 to string-length($str)
5 for $scp in string-to-codepoints($str)[$i]
6 return concat($scp, "-" , $i , "-" , $a )
7 '
8 ) t;Result Sequence
--------------------------------------------------------------------------------
65-1-1
66-1-1
67-1-1
68-1-1
The visibility of $i and $a in the return statement is where I see issue whereas it is able to use the correct value in the inner for statement to pick the correct index.
My expected result is as in any of the following statements.