LEAVE statement

The LEAVE statement transfers program control out of a loop or a compound statement.

Syntax

Read syntax diagramSkip visual syntax diagramLEAVElabel

Description

label
Specifies the label of the compound statement or loop to exit.

A label name cannot be the same as the name of the SQL procedure in which the label is used.

Notes

When a LEAVE statement transfers control out of a compound statement, all open cursors in the compound statement, except cursors that are used to return result sets, are closed.

Examples

Use a LEAVE statement to transfer control out of a LOOP statement when a negative SQLCODE occurs.

ftch_loop: LOOP
 FETCH c1 INTO
  v_firstnme, v_midinit,
  v_lastname, v_edlevel, v_salary;
 IF SQLCODE=100 THEN LEAVE ftch_loop;
 END IF;
END LOOP