MySQL 'Truncated incorrect INTEGER value'

前端 未结 6 1451
野趣味
野趣味 2020-12-11 01:57

I\'m getting an odd \'Truncated incorrect INTEGER value\' error when I run the following UPDATE query:

update tbl
set projectNumber = right(comments, 7)
wher         


        
6条回答
  •  既然无缘
    2020-12-11 02:31

    It's not an error. It's a warning that comes from CONVERT() when you ask it to convert non-numeric to integer;

    Run these queries in console to see:

    mysql> SELECT CONVERT(right('1s23d45678', 7), SIGNED INTEGER);
    +-------------------------------------------------+
    | CONVERT(right('1s23d45678', 7), SIGNED INTEGER) |
    +-------------------------------------------------+
    |                                               3 |
    +-------------------------------------------------+
    1 row in set, 1 warning (0.00 sec)
    
    mysql> SHOW WARNINGS;
    +---------+------+----------------------------------------------+
    | Level   | Code | Message                                      |
    +---------+------+----------------------------------------------+
    | Warning | 1292 | Truncated incorrect INTEGER value: '3d45678' |
    +---------+------+----------------------------------------------+
    1 row in set (0.00 sec)
    

    As I said, it's a warning, not an error. Your query should be doing the update correctly.

提交回复
热议问题