LEAVE to a label : LEAVE « Procedure Function « SQL / MySQL






LEAVE to 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=1) THEN
    ->                         LEAVE inner_block;
    ->                 END IF;
    ->                 SELECT 'This statement will never be executed';
    ->         END inner_block;
    ->         SELECT 'End of program';
    -> END outer_block$$
Query OK, 0 rows affected (0.00 sec)

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

Query OK, 0 rows affected (0.02 sec)

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

mysql>
mysql>
mysql>

          
  








Related examples in the same category

1.LEAVE with Label out of an inner loop
2.Break out from a procedure with leave statement