在 MySQL 的存储过程中实现 If else?
mysqlmysqli database更新于 2024/10/9 22:36:17
要实现 if-else,语法如下 −
if yourCondition then yourStatement1; else yourStatement2; end if ;
为了理解存储过程中 if-else 的上述概念,让我们创建一个存储过程 −
mysql> delimiter // mysql> create procedure If_else_stored_demo(value int) begin if value > 1000 then select "your value is greater than 1000"; else select "your value is less than or equal to 1000"; end if ; end // Query OK, 0 rows affected (0.00 sec) mysql> delimiter ;
现在您可以使用 call 命令调用存储过程 −
mysql> call If_else_stored_demo(500);
这将产生以下输出 −
+------------------------------------------+ | your value is less than or equal to 1000 | +------------------------------------------+ | your value is less than or equal to 1000 | +------------------------------------------+ 1 row in set (0.00 sec) Query OK, 0 rows affected (0.00 sec)
相关文章
有用资源
mysql 参考教程 - 该教程包含有关 mysql 的更多信息:https://www.cainiaomax.com/mysql/

