Home > Database > Mysql Tutorial > How does a MySQL stored procedure call multiple procedures?

How does a MySQL stored procedure call multiple procedures?

WBOY
Release: 2023-08-23 17:17:02
forward
818 people have browsed it

How does a MySQL stored procedure call multiple procedures?

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 //
Copy after login

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)
Copy after login

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 ;
Copy after login

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 ;
Copy after login

Now you can call the main stored procedure −

mysql> call call_all_stored_procedure();
Copy after login

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)
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template