gpt4 book ai didi

mysql - 我可以在 MySQL 存储过程中覆盖 IN 参数吗

转载 作者:行者123 更新时间:2023-11-29 16:12:54 25 4
gpt4 key购买 nike

我可以覆盖 MySQL 存储过程中的 IN 参数吗?

也就是说,我可以做这样的事情:

create procedure proc1 (IN p_parm1 int)
begin
if p_parm1 is null then
**set p_parm1 = -1;**
end if
end $$

最佳答案

你应该像这样自己测试一下:

mysql> create procedure proc1 (IN p_parm1 int) begin
if p_parm1 is null then
set p_parm1 = -1;
end if;
select p_parm1;
end$$
Query OK, 0 rows affected (0.02 sec)

mysql> call proc1(123)$$
+---------+
| p_parm1 |
+---------+
| 123 |
+---------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

mysql> call proc1(null)$$
+---------+
| p_parm1 |
+---------+
| -1 |
+---------+
1 row in set (0.00 sec)

Query OK, 0 rows affected (0.00 sec)

所以答案是肯定的,您可以更改输入的值。在您的示例中,您可以有效地为输入参数指定一个默认值,以防它为 null。

关于mysql - 我可以在 MySQL 存储过程中覆盖 IN 参数吗,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/55095304/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com