我可以覆盖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。