Home  >  Article  >  Database  >  How to exit a MySQL stored procedure?

How to exit a MySQL stored procedure?

WBOY
WBOYforward
2023-09-13 23:33:111722browse

How to exit a MySQL stored procedure?

We can use the LEAVE command to exit the MySQL stored procedure.

The following is the syntax.

Leave yourLabelName;

Below is an example. Here we are creating a new process.

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 set the following LEAVE command to exit the program. If Var1 is "NULL", the program will exit.

LEAVE proc_Exit;

Change the delimiter to ";".

mysql>delimiter ;
mysql>

To call a stored procedure, we need to use the CALL command, followed by the procedure name.

The following is the syntax.

call yourStoredProcedureName;

The above is the detailed content of How to exit a MySQL stored procedure?. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete
Previous article:Install MySQL on macOSNext article:Install MySQL on macOS