数据库
首页 > 数据库> > 在更新语句中使用强制转换时,mysql错误1292

在更新语句中使用强制转换时,mysql错误1292

作者:互联网

下面的语句返回“错误代码:1292.截断了不正确的INTEGER值:’95 .00’1.132秒”

update new2006 set new2006.emp=cast(emp as unsigned) where IsNum(emp)=0;

但是,如果使用以下语句,则可以成功获得结果95.

select cast(emp as unsigned) from new2006 where IsNum(emp)=0;

谁能帮我?提前致谢.

PS:emp的数据类型为varchar(7).

解决方法:

您处于严格的SQL mode;如所记录(强调):

Strict mode controls how MySQL handles invalid or missing values in data-change statements such as 07001 or 07002. A value can be invalid for several reasons. For example, it might have the wrong data type for the column, or it might be out of range. A value is missing when a new row to be inserted does not contain a value for a non-NULL column that has no explicit DEFAULT clause in its definition. (For a NULL column, NULL is inserted if the value is missing.)

For statements that do not change data, such as 07003, invalid values generate a warning in strict mode, not an error.

如果您希望UPDATE成功而不出错,则需要更改为非严格SQL模式,否则首先将字符串处理为不会引发错误的值,例如SUBSTRING_INDEX(emp,’.’,1).

标签:mysql,truncated
来源: https://codeday.me/bug/20191013/1907695.html