当我尝试运行以下查询时,我收到Truncated incorrect INTEGER value: 'D'
警告:
UPDATE MESSAGES
SET status = CASE
WHEN
(from_id='111111111' AND status='A') THEN 'S'
WHEN
(to_id ='111111111' AND status='A') THEN 'R'
WHEN
((from_id ='111111111' AND status='R') OR
(to_id ='111111111' AND status='S')) THEN 'D'
END
WHERE primary_key = '236499681204'
AND
(CASE
WHEN
(from_id='111111111' AND status='A') THEN 'S'
WHEN
(to_id ='111111111' AND status='A') THEN 'R'
WHEN
((from_id ='111111111' AND status='R') OR
(to_id ='111111111' AND status='S')) THEN 'D'
END) is not null
我已阅读帖子MySQL 'Truncated incorrect INTEGER value'和MYSQL Truncated incorrect INTEGER value error。但他们不适用于我的情况。此处status
的类型为VARCHAR(1)
。
我有什么遗失的吗?
修改
以下是创建表的查询:
CREATE TABLE `MESSAGES` (
`primary_key` bigint(12) unsigned NOT NULL AUTO_INCREMENT,
`from_id` varchar(9) NOT NULL,
`to_id` varchar(9) NOT NULL,
`status` varchar(1) NOT NULL,
PRIMARY KEY (`primary_key`)
) ENGINE=MyISAM AUTO_INCREMENT=123456789876 DEFAULT CHARSET=latin1
请帮助:(
答案 0 :(得分:4)
这不是因为status
而是因为比较
(CASE
WHEN
(from_id='111111111' AND status='A') THEN 'S'
WHEN
(to_id ='111111111' AND status='A') THEN 'R'
WHEN
((from_id ='111111111' AND status='R') OR
(to_id ='111111111' AND status='S')) THEN 'D'
END) is not null
为避免错误,请将CASE
的结果投射到这样的CHAR
中:
CAST( (CASE
WHEN
(from_id='111111111' AND status='A') THEN 'S'
WHEN
(to_id ='111111111' AND status='A') THEN 'R'
WHEN
((from_id ='111111111' AND status='R') OR
(to_id ='111111111' AND status='S')) THEN 'D'
END) AS CHAR) is not null
现在它应该可以正常工作:)