XML Database (MOSC)

MOSC Banner

The variable in the outer FOR loop shows incorrect value in the inner nested FOR loop

edited Jan 18, 2020 4:02AM in XML Database (MOSC) 4 commentsAnswered

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.

Howdy, Stranger!

Log In

To view full details, sign in to My Oracle Support Community.

Register

Don't have a My Oracle Support Community account? Click here to get started.

Category Leaderboard

Top contributors this month

New to My Oracle Support Community? Visit our Welcome Center

MOSC Help Center