I have a stored procedure where the IN
parameter is INT
.
我有一个存储过程,其中IN参数是INT。
Sometimes, when I need no values for this IN
parameter, I need to pass null
. But I get the error /* SQL Error (1366): Incorrect integer value: 'NULL' for column 'xStatus' at row 2 */
How can I pass NULL when it's an INT.
有时,当我不需要这个IN参数的值时,我需要传递null。但是我收到错误/ * SQL错误(1366):错误的整数值:第2行的'xStatus'列''''如果是INT,我怎么能传递NULL。
CREATE DEFINER=`root`@`localhost` FUNCTION `links`(`xStatus` INT(2))
RETURNS varchar(2400)
LANGUAGE SQL
NOT DETERMINISTIC
CONTAINS SQL
SQL SECURITY DEFINER
COMMENT ''
BEGIN
DECLARE output varchar(50);
CASE xStatus WHEN NULL THEN
SET output = 'Is Null';
ELSE
SET output = 'Was not Null';
END CASE;
return output;
END
1 个解决方案
#1
1
Here's one way you can write this:
这是你可以这样写的一种方式:
Create Function links(xstatus int) returns varchar(2400) language sql
begin
return
case
when xstatus is null then 'is null'
else 'is not null'
end;
end;
#1
1
Here's one way you can write this:
这是你可以这样写的一种方式:
Create Function links(xstatus int) returns varchar(2400) language sql
begin
return
case
when xstatus is null then 'is null'
else 'is not null'
end;
end;