我正在运行查询并获取mysql错误1292:“截断的INTEGER值不正确” 这是一个警告,我的选择工作正常,但我仍然想清除警告。
我可以确认每次函数找到链接到对象的标记时都会发出警告。如果未找到任何标记,则不会发出警告。因此,如果1000个对象中有50个具有标签,我将收到50个警告,如下所示:
Truncated incorrect INTEGER value: '1|Blondes'
使用的数据库功能是:
DELIMITER $$
DROP FUNCTION IF EXISTS `fnObjectTagGetObjectTags` $$
CREATE DEFINER=`root`@`%` FUNCTION `fnObjectTagGetObjectTags`(_objectType int, _objectId bigint) RETURNS varchar(2048) CHARSET utf8
BEGIN
DECLARE _outObjectTags VARCHAR(2048);
SET _outObjectTags =
(
SELECT (CAST(GROUP_CONCAT(CONCAT(tagId, '|', tagName) separator '~') AS CHAR(10000) CHARACTER SET utf8)) AS objectTagList
FROM
(
SELECT tagId, tagName
FROM objectTag
INNER JOIN tag
ON tagId = objectTagTagId
WHERE objectTagObjectType = _objectType
AND objectTagObjectId = _objectId
AND objectTagIsDisabled = 0
AND objectTagIsActive = 1
AND tagIsDisabled = 0
AND tagIsActive = 1
) as subQuery
);
RETURN _outObjectTags;
END $$
DELIMITER ;
调用查询只是:
SELECT fnObjectTagGetObjectTags(3, album.albumId)
FROM album
WHERE fnObjectTagGetObjectTags(3, album.albumId) IS NOT NULL
AND albumIsDisabled = 0
AND albumIsActive = 1
我无法弄清楚为什么会这样做。有人看到奇怪吗? 我正在运行5.5.13 感谢
答案 0 :(得分:2)
在连接之前尝试将tagId显式转换为字符,因为您可能混合使用二进制和非二进制字符串。喜欢
SELECT (CAST(GROUP_CONCAT(CONCAT(CAST(tagId AS CHAR), '|', tagName) separator '~') AS CHAR(10000) CHARACTER SET utf8))