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同樣的報錯