Home >Database >Mysql Tutorial >Using IF logic to call a stored procedure within a stored procedure?
To call a stored procedure within a stored procedure, the syntax is as follows -
If yourInputValue > 100 then call yourProcedureName1(); else call yourProcedureName2(); end If ; END
Let us implement the above syntax. To implement the above concept, let us create a stored procedure -
mysql> delimiter // mysql> create procedure Hello_Stored_Procedure() -> BEGIN -> select 'Hello World!!!'; -> END -> // Query OK, 0 rows affected (0.18 sec)
The query to create the second stored procedure is as follows -
mysql> create procedure Hi_Stored_Procedure() -> BEGIN -> select 'Hi!!!'; -> END -> // Query OK, 0 rows affected (0.17 sec)
Here is the query to call the stored procedure using IF logic -
mysql> DELIMITER // mysql> create procedure test(IN input int) -> BEGIN -> If input > 100 then -> call Hello_Stored_Procedure(); -> else -> call Hi_Stored_Procedure(); -> end If ; -> END -> // Query OK, 0 rows affected (0.18 sec)
Now you can call the stored procedure with the help of call -
mysql> delimiter ; mysql> call test(110);
This will produce the following output-
+----------------+ | Hello World!!! | +----------------+ | Hello World!!! | +----------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.02 sec)
The above is the detailed content of Using IF logic to call a stored procedure within a stored procedure?. For more information, please follow other related articles on the PHP Chinese website!