LEAVE to a label : LEAVE : Procedure Function MySQL TUTORIALS


MySQL TUTORIALS » Procedure Function » LEAVE »

 

LEAVE to a label


LEAVE label

LEAVE label statement is used to exit any labeled flow control construct.

It can be used within BEGIN ... END or loop constructs (LOOP, REPEAT, WHILE).

The LEAVE statement must be accompanied by a label.

mysql>
mysql> delimiter $$
mysql>
mysql> CREATE PROCEDURE myProc()
    ->  outer_block: BEGIN
    ->         DECLARE l_status int;
    ->         SET l_status=1;
    ->         inner_block: BEGIN
    ->                 IF (l_status=1THEN
    ->                         LEAVE inner_block;
    ->                 END IF;
    ->                 SELECT 'This statement will never be executed';
    ->         END inner_block;
    ->         SELECT 'End of program';
    -> END outer_block$$
Query OK, rows affected (0.00 sec)

mysql> delimiter ;
mysql> call myProc();
+----------------+
End of program |
+----------------+
End of program |
+----------------+
row in set (0.00 sec)

Query OK, rows affected (0.02 sec)

mysql> drop procedure myProc;
Query OK, rows affected (0.00 sec)

mysql>
mysql>
mysql>



Leave a Comment / Note


 
Verification is used to prevent unwanted posts (spam). .

Follow Navioo On Twitter

MySQL TUTORIALS

 Navioo Procedure Function
» LEAVE