First let us look at the syntax in which we call multiple procedures from a stored procedure −
DELIMITER // CREATE PROCEDURE yourProcedureName() BEGIN CALL yourStoredProcedureName1(); CALL yourStoredProcedureName2(); . . N END // DELIMITER //
Let us implement the above syntax to call multiple stored procedures.
The following is the query to create the first stored procedure:
mysql> DELIMITER // mysql> CREATE PROCEDURE hello_message() -> BEGIN -> SELECT 'HELLO WORLD !!'; -> END -> // Query OK, 0 rows affected (0.19 sec)
The query to create the second stored procedure is as follows −
mysql> CREATE PROCEDURE hi_message() -> BEGIN -> SELECT 'HI !!!!'; -> END -> // Query OK, 0 rows affected (0.11 sec) mysql> DELIMITER ;
Here is to create a new stored procedure to Query statement that calls multiple stored procedures −
mysql> DELIMITER // mysql> CREATE PROCEDURE call_all_stored_procedure() -> BEGIN -> CALL hello_message(); -> CALL hi_message(); -> END -> // Query OK, 0 rows affected (0.26 sec) mysql> DELIMITER ;
Now you can call the main stored procedure −
mysql> call call_all_stored_procedure();
This will produce the following output −
+----------------+ | HELLO WORLD !! | +----------------+ | HELLO WORLD !! | +----------------+ 1 row in set (0.06 sec) +---------+ | HI !!!! | +---------+ | HI !!!! | +---------+ 1 row in set (0.06 sec) Query OK, 0 rows affected (0.08 sec)
The above is the detailed content of How does a MySQL stored procedure call multiple procedures?. For more information, please follow other related articles on the PHP Chinese website!