使用 IF 逻辑在存储过程中调用存储过程?
mysqlmysqli database更新于 2024/8/11 6:36:17
要在存储过程中调用存储过程,语法如下 −
If yourInputValue > 100 then call yourProcedureName1(); else call yourProcedureName2(); end If ; END
让我们实现上述语法。为了实现上述概念,让我们创建一个存储过程 −
mysql> delimiter // mysql> create procedure Hello_Stored_Procedure() -> BEGIN -> select 'Hello World!!!'; -> END -> // Query OK, 0 rows affected (0.18 sec)
创建第二个存储过程的查询如下 −
mysql> create procedure Hi_Stored_Procedure() -> BEGIN -> select 'Hi!!!'; -> END -> // Query OK, 0 rows affected (0.17 sec)
这是使用 IF 逻辑在存储过程内调用存储过程的查询 −
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)
现在您可以借助 call 来调用存储过程 −
mysql> delimiter ; mysql> call test(110);
这将产生以下输出 −
+----------------+ | Hello World!!! | +----------------+ | Hello World!!! | +----------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.02 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

