Err 1292 - 截断错误的DOUBLE值:' 70,40,77,28,23,72,82,38,29'

时间:2016-05-30 08:11:30

标签: mysql

当我像这样执行这个功能时:

enter image description here

这是我定义的函数:

CREATE FUNCTION kyf_getFormationComat(heroSdIds VARCHAR(128), uid VARCHAR(128))
RETURNS INT(11)
BEGIN
    DECLARE comat INT(11);
    SET comat = (SELECT SUM(a.comat) FROM ky_heroinfo a WHERE a.uid = uid AND a.staticdata_id in (heroSdIds));
    RETURN comat;
END

1 个答案:

答案 0 :(得分:0)

heroSdIds是一个字符串,因此您无法在IN()查询中使用SELECT

SELECT SUM(a.comat) FROM ky_heroinfo a 
    WHERE a.uid = uid AND a.staticdata_id in (heroSdIds)

条件:

a.staticdata_id in (heroSdIds)

实际上给了你:

a.staticdata_id in ("70,40,77,28,23,72,82,38,29") 

请注意引号。它仍然是一个字符串,这里是单值。但为了使其有效,IN()将要求它是用逗号分隔的多个值:

a.staticdata_id in (70,40,77,28,23,72,82,38,29) 

要使其正常工作,您可以尝试使用字符串函数FIND_IN_SET()函数而不是IN()

尝试:

FIND_IN_SET(a.staticdata_id, heroSdIds)

所以整个查询将是:

SELECT SUM(a.comat) FROM ky_heroinfo a 
    WHERE a.uid = uid AND FIND_IN_SET(a.staticdata_id, heroSdIds)