- You can qualify LOOP with a statement label.
A LEAVE statement specified within the LOOP breaks the iteration statement, passing control to the next statement following the statement with that label.
- You must specify a LEAVE statement inside the LOOP statement to make sure of normal termination of the statement.
If you do not, the loop iterates continuously and can only be stopped by an asynchronous abort.
- Causes of LOOP-Terminating Errors
- If a statement in the LOOP raises an exception condition and a CONTINUE handler has been declared for that condition, then the stored procedure execution continues.
- If an EXIT handler has been declared, then the statement terminates the stored procedure execution.
- If a statement within the loop raises an error condition and its associated SQLSTATE code is not defined for a handler, then both the loop and the stored procedure terminate.