SELECT...INTO 在存储过程中返回 null [英] SELECT...INTO returns null in Stored Procedure

查看:54
本文介绍了SELECT...INTO 在存储过程中返回 null的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

这个函数:

CREATE FUNCTION `GetCardID`(numId INT) RETURNS int(11)
    DETERMINISTIC
BEGIN
    DECLARE retcard INT(11);
    SELECT id
    INTO retcard
    FROM cards
    WHERE `number` = numId
        AND enabled = 1
    LIMIT 1;
    RETURN retcard;
END

即使在查询时也始终返回 null:

Always returns null even when the query:

SELECT id FROM cards WHERE `number`=<Insert Value Here> AND ENABLED = 1 LIMIT 1;

为函数参数中使用的相同值返回一个有效值.

returns a valid value for the same value used in and the function parameter.

例如:
SELECT id FROM card WHERE number=12345 AND ENABLED = 1 LIMIT 1;
-- 返回一个id,而
GetCardId(12345);
-- 返回空

For instance:
SELECT id FROM cards WHERE number=12345 AND ENABLED = 1 LIMIT 1;
-- returns an id, while
GetCardId(12345);
-- returns null

知道我在这里缺少什么吗?我认为自己在 SQL 方面相当熟练,但在 SP 方面有点绿色.

Any ideas what I'm missing here? I consider myself quite skilled at SQL, but a little green on SP's.

推荐答案

您在函数中使用的数据有多大?这个数字有没有可能比 INT 能容纳的还大?

How big is the data that you are taking into your function? Is it possible that the number is larger than what will fit into an INT?

这篇关于SELECT...INTO 在存储过程中返回 null的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆