LEAVE statement (Exit statement)

Function

The LEAVE statement exits from a compound statement, the WHILE statement, or the FOR statement, and terminates the execution of those statements.

Format

LEAVE [statement-label]

Operand

Specifies the statement label for the compound statement, WHILE statement, or FOR statement from which control exits, and the execution of which is to be terminated.

If the statement label is omitted, the execution of the innermost compound statement surrounding the LEAVE statement from which the statement label was omitted, the WHILE statement, or the FOR statement is terminated prematurely.

Common rules

  1. For a statement label, specify the starting label of the statement (compound statement, WHILE statement, or FOR statement) that includes the LEAVE statement.
  2. The LEAVE statement that causes control to leave the handler action cannot be specified in the handler action.

Note

  1. LEAVE statements can be specified in an SQL routine.