We can quit/ exit from MySQL stored procedure with the help of the LEAVE command.
The following is the syntax.
Leave yourLabelName;
The following is an example. Here, we are creating a new procedure.
mysql> delimiter // mysql> CREATE PROCEDURE ExitQuitDemo2(IN Var1 VARCHAR(20)) -> proc_Exit:BEGIN -> IF Var1 IS NULL THEN -> LEAVE proc_Exit; -> END IF; -> END // Query OK, 0 rows affected (0.16 sec)
Above, we have set the following LEAVE command to exit from the procedure. If Var1 is “NULL”, the procedure will exit.
LEAVE proc_Exit;
To change the delimiter to ‘;’.
mysql>delimiter ; mysql>
To call stored procedure, we need to use CALL command followed by the procedure name.
The following is the syntax.
call yourStoredProcedureName;