|
REPEAT Statement | Control Statements | FOR Statement |
statement_LEAVE ::= LEAVE label;
The LEAVE statement aborts the execution of statements in a block statement, LOOP statement, REPEAT statement, WHILE statement or FOR statement and continues with the next statement after the label.
The label must be identical to some label of the statement containing the LEAVE statements. If the LEAVE statement is used for aborting a block statement which is a part of a procedure body, it is possible to use the procedure name as the label.
You may also use a label from a procedure that is calling the procedure containing the LEAVE statement. If no label is found, the procedure will terminate without error.
Example:
Pass through the cursor records. Do nothing for 'New York' companies (and LEAVE this loop iteration) and LEAVE the loop when a NULL value is found.
PROCEDURE `LEAVE_ATTEMPT`();
BEGIN
FOR_loop: FOR row AS c CURSOR FOR
SELECT * FROM Companies
DO
this_record: BEGIN
...
CALL Log_write('before '||row.address);
IF row.address LIKE 'New York%' THEN LEAVE this_record; END IF;
IF row.address IS NULL THEN LEAVE FOR_loop; END IF;
CALL Log_write('after '||row.address);
...
END;
END FOR;
CALL Log_write('...after FOR loop...');
END
Leave procedure
PROCEDURE LEAVE_ATTEMPT2();
BEGIN
...
IF ... THEN LEAVE LEAVE_ATTEMPT2; END IF;
...
END
REPEAT Statement | Control Statements | FOR Statement |