ERROR 1292 (22007): Truncated incorrect DOUBLE value 和ORA-01722: invalid number
其实这种错误和隐式转换有关
主要是由于转换的时候不能转换为期望的格式的然后出的问题
比如 1p这个字符要转换为 int(number)是不可能的
MYSQL 错误模拟如下:
myql> show variables like 'sql_mode%';
+---------------+--------------------------------------------+
| Variable_name | Value |
+---------------+--------------------------------------------+
| sql_mode | STRICT_TRANS_TABLES,NO_ENGINE_SUBSTITUTION |
+---------------+--------------------------------------------+
1 row in set (0.01 sec)
mysql> use test
Reading table information for completion of table and column names
You can turn off this feature to get a quicker startup with -A
Database changed
mysql> create table jjjkk (id varchar(20),name varchar(20));
Query OK, 0 rows affected (0.03 sec)
mysql> insert into jjjkk values('1','gaopeng');
Query OK, 1 row affected (0.00 sec)
mysql> update jjjkk set name='gaop' where id=1;
Query OK, 1 row affected (0.05 sec)
Rows matched: 1 Changed: 1 Warnings: 0
mysql> update jjjkk set name='gaop' where id=1;
Query OK, 0 rows affected (0.00 sec)
Rows matched: 1 Changed: 0 Warnings: 0
mysql> insert into jjjkk values('1p','gaopeng');
Query OK, 1 row affected (0.01 sec)
mysql> commit;
Query OK, 0 rows affected (0.00 sec)
mysql> update jjjkk set name='gaop' where id=1;
ERROR 1292 (22007): Truncated incorrect DOUBLE value: '1p'
MYSQL 中存在隐式转换ORACLE中通常会在执行计划中给出to_char之类的标示
但是MYSQL执行计划没有
如上列子虽然'1'可以转换这个时候没有报错。但是新插入的'1p'是不能转换的
这个在ORACLE中也存在这样的问题。所以报错
ERROR 1292 (22007): Truncated incorrect DOUBLE value: '1p'
当然我是严格的SQL_MODE,否则则是WARINGS
可以如下试试转换:
SELECT CONVERT('1',SIGNED);
SELECT CONVERT('1p',SIGNED);
然后演示一下ORACLE的报错:
SQL> create table testmmm( id varchar2(20),name varchar2(20));
Table created
SQL> insert into testmmm values('1','gaopeng');
1 row inserted
SQL> commit;
Commit complete
SQL> select * from testmmm where id=1;
ID NAME
-------------------- --------------------
1 gaopeng
SQL> insert into testmmm values('1p','gaopeng');
1 row inserted
SQL> commit;
Commit complete
SQL> select * from testmmm where id=1;
select * from testmmm where id=1
ORA-01722: invalid number
如果模拟
SQL> select to_number('1p') from dual;
select to_number('1p') from dual
ORA-01722: invalid number
同样的情况
我们查看一下执行计划中的隐式转换信息:
Predicate Information (identified by operation id):
---------------------------------------------------
1 - filter(TO_NUMBER("ID")=1)
仅此记录MYSQL和ORACLE同样的报错