MySQL procedure to call multiple procedures?

MySQLMySQLi Database

Let us first see the syntax, wherein we are calling 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.

Following is the query to create 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 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 the query to create a new procedure to call 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)
raja
Published on 12-Nov-2019 11:14:03
Advertisements