ERROR 1292(22007)

ERROR 1292(22007)

Table of Contents

1 1292

 

1.1 22007

  • 錯誤信息css

    ERROR 1292 (22007): Truncated incorrect DOUBLE value: ''
    
  • 分析html

    該錯誤是因爲 MySQL 對字符值是否符合字段要求進行了嚴格的檢查,可是有時候,這個 檢查的結果倒是錯誤的。就像下面示例:java

    MariaDB [(none)]> update test.test set status=NULL where status=6;
    
    ERROR 1292 (22007): Truncated incorrect DOUBLE value: ''
    
    MariaDB [(none)]> desc test.test;
    +---------------------+--------------+------+-----+---------+----------------+
    | Field               | Type         | Null | Key | Default | Extra          |
    +---------------------+--------------+------+-----+---------+----------------+
    | id                  | bigint(20)   | NO   | PRI | NULL    | auto_increment |
    | status              | varchar(30)  | YES  |     | NULL    |                |
    +---------------------+--------------+------+-----+---------+----------------+
    2 rows in set (0.02 sec)
    

    從上面的查詢結果來看,status 字段容許爲空, 默認爲空。我將該字段值更新爲空字段並 沒有違反該字段的約束條件。可是,錯誤就是麼離奇的發生了。明明沒有問題,卻提示爲錯誤 數據。python

  • 查看SQL_MODEsql

      MariaDB [(none)]> show variables like 'sql_mode';
    +---------------+-------------------------------------------------------------------------------------------+
    | Variable_name | Value                                                                                     |
    +---------------+-------------------------------------------------------------------------------------------+
    | sql_mode      | STRICT_TRANS_TABLES,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION |
    +---------------+-------------------------------------------------------------------------------------------+
    
  • 解決shell

         主要是把sql_mode中的strict_trans_tables去掉便可。sass

set [global | session] variables sql_mode = 'ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION';

Author: halberd.leeruby

Created: 2019-07-16 Tue 13:58bash

Validatebabel

相關文章
相關標籤/搜索