Show TOC

LEAVE StatementLocate this document in the navigation structure

Continues execution by leaving a compound statement or LOOP.

Syntax
LEAVE <statement-label>
Examples

(back to top)

  • Example 1 this code fragment shows how to use the LEAVE statement to leave a loop:
    SET i = 1;
    lbl:
    LOOP
      INSERT
      INTO Counters ( number )
      VALUES ( i ) ;
      IF i >= 10 THEN
        LEAVE lbl ;
      END IF ;
      SET i = i + 1
    END LOOP lbl
  • Example 2 this code fragment uses LEAVE in a nested loop:
    outer_loop:
    LOOP
      SET i = 1;
      inner_loop:
      LOOP
        ...
        SET i = i + 1;
        IF i >= 10 THEN
          LEAVE outer_loop
        END IF
      END LOOP inner_loop
    END LOOP outer_loop
Usage

(back to top)

LEAVE is a control statement that lets you leave a labeled compound statement or a labeled loop. Execution resumes at the first statement after the compound statement or loop.

The compound statement that is the body of a procedure has an implicit label that is the same as the name of the procedure.

Standards

(back to top)

  • SQL—ISO/ANSI SQL compliant.
  • SAP Database products—Not supported in SAP ASE. The break statement provides a similar feature for Transact-SQL compatible procedures.
Permissions