错误代码:1292 - 截断不正确的DOUBLE值:' - '

时间:2015-03-12 11:40:13

标签: mysql sql mysql-error-1292

SET @newNum = IF(
    RIGHT("-600.00",1) REGEXP '^[-]' = '-',
    REPLACE("-600.00",",",""),
    -1*REPLACE(REPLACE("-600.00",",",""),"-","")
);

我不断得到一个截断不正确的DOUBLE值:' - '执行此行时,任何人都知道导致这种情况的原因是什么?

1 个答案:

答案 0 :(得分:0)

REGEXP返回1或0,具体取决于是否匹配。将结果与-进行比较是不正确的,您可以改为:

DECLARE @oldNum VARCHAR(10);
DECLARE @newNum VARCHAR(10);
SET @oldNum = '600.00-';
SET @newNum = IF(
    RIGHT(@oldNum, 1) = '-',
    CONCAT('-', REPLACE(REPLACE(@oldNum, ',', ''), '-', '')),
                        REPLACE(@oldNum, ',', '')
);
SELECT @oldNum, @newNum