1 Reply Latest reply: Dec 4, 2012 3:46 AM by AbhishekJ RSS

    Exiting a for loop in the middle of iteration in XQuery

    CH.ADITYA
      Hi,

      I have below xquery block.

      <Root>
           {
      for $line in $body/input/item
           if($line eq "E") then (
           return "1"
           )
           else("0")
      }
      </Root>

      My task here is I have to iterate through all the line items and if I encounter "E" even in single case I have to exit imediately the for loop by returning "1", if it is not "E" for all the line items then at the end I shud return "0"

      Here I'm not able to exit the for loop. Do we have any predefined keyword for exiting the loop?

      Thanks in advance.
        • 1. Re: Exiting a for loop in the middle of iteration in XQuery
          AbhishekJ
          Why are you running a look for this? You can do it without a loop:
          <Root>
          {
          if(fn:exists( $body/input[item/text() = 'E'])) then (
          return "1"
          )
          else("0")
          }
          </Root>
          And to answer your original question, XQuery by itself does not have a break or an exit function or statement to come out of a For loop. There is an XQuery scripting extension which supports it but not sure if it is supported by Oracle products.