Contents Index INTERSECT operation LOAD STATISTICS statement

ASA SQL Reference
  SQL Statements

LEAVE statement


Description 

Use this statement to leave a compound statement or loop.

Syntax 

LEAVE statement-label

See also 

LOOP statement

FOR statement

BEGIN statement

Using Procedures, Triggers, and Batches

Usage 

The LEAVE statement is a control statement that allows you to 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 or trigger has an implicit label that is the same as the name of the procedure or trigger.

Permissions 

None.

Side effects 

None.

Standards and compatibility 
Example 

The following fragment shows how the LEAVE statement is used 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

The following example 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

Contents Index INTERSECT operation LOAD STATISTICS statement