The LEAVE statement can be used to terminate the execution of a procedural-sql-statement. For a list of procedural SQL statements, see Procedural SQL Statements.
The label is the beginning label of a procedural-sql-statement within the scope containing the LEAVE statement.
A procedural-sql-statement must have a beginning label if LEAVE is to be used to terminate its execution.
All intervening compound statements between the statement identified by the label and the leave statement will be left. The following actions occur before execution of the compound statements is terminated, after the LEAVE statement is executed:
•Every open cursor declared in the compound statements is closed.
•All variables, cursors and handlers declared in the compound statements are destroyed.
•All condition names declared in the compound statements cease to be defined.
If the LEAVE statement is executed within a compound statement forming the body of a procedure, execution of the procedure will be terminated.
CREATE PROCEDURE procedure_name(INOUT Y INTEGER)
IF Y < 0 THEN
SET Y = 0;
Features outside core
Feature P002, “Computational completeness”.