不正确的十进制(整数)值:“ ” mySQL
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/35037288/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Incorrect decimal (integer) value: ' ' mySQL
提问by Maha
In mySQL workbench database, one of the tables has latitude, longitude and district attributes
在mySQL工作台数据库中,其中一张表具有纬度、经度和地区属性
lat: decimal (10,8)
纬度:十进制(10,8)
lng: decimal (11,8)
lng:十进制 (11,8)
district: int(4)
地区:int(4)
I'm trying to import data from .csv file to this table
我正在尝试将 .csv 文件中的数据导入此表
ERROR 1366: 1366: Incorrect decimal value: '' for column 'lat' at row 1
SQL Statement:
ERROR 1366: 1366: Incorrect integer value: '' for column 'district' at row 1
SQL Statement:
INSERT INTO `db`.`myTable` (`id`, `name_en`, `icon`, `lat`, `lng`, `district`, `city`, `postal_code`)
VALUES ('686', 'Name',?, '', '', '','1', 'P.O. Box 1111')
回答by Shadow
You have strict sql mode enabled, and you try to pass an empty string ('') as value for decimal fields in the insert. Empty string is an invalid value for a numeric field and in strict sql modemysql generates an error if you try to insert an invalid data into a column, rather than providing a warning and use the default value (0 for numeric columns) of the particular column's data type:
您启用了严格的 sql 模式,并且您尝试将空字符串 ('') 作为插入中的十进制字段的值传递。空字符串是数字字段的无效值,并且在严格的 sql 模式下,如果您尝试将无效数据插入列中,mysql 会生成错误,而不是提供警告并使用特定值的默认值(数字列为 0)列的数据类型:
Strict mode controls how MySQL handles invalid or missing values in data-change statements such as INSERT or UPDATE. 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.) Strict mode also affects DDL statements such as CREATE TABLE.
If strict mode is not in effect, MySQL inserts adjusted values for invalid or missing values and produces warnings (see Section 13.7.5.40, “SHOW WARNINGS Syntax”). In strict mode, you can produce this behavior by using INSERT IGNORE or UPDATE IGNORE.
严格模式控制 MySQL 如何处理数据更改语句(如 INSERT 或 UPDATE)中的无效或缺失值。由于多种原因,值可能无效。例如,它可能具有错误的列数据类型,或者可能超出范围。当要插入的新行不包含在其定义中没有显式 DEFAULT 子句的非 NULL 列的值时,缺少值。(对于 NULL 列,如果缺少值,则插入 NULL。)严格模式也会影响 DDL 语句,例如 CREATE TABLE。
如果严格模式无效,MySQL 会为无效或缺失值插入调整后的值并产生警告(参见第 13.7.5.40 节,“显示警告语法”)。在严格模式下,您可以通过使用 INSERT IGNORE 或 UPDATE IGNORE 来产生这种行为。
Remove the strict sql mode for the session before starting the import:
在开始导入之前删除会话的严格 sql 模式:
SET SESSION sql_mode = ''
回答by Sadee
Remove STRICT_TRANS_TABLEfrom global sql_mode
. You might required other attributes such as NO_ZERO_DATEin global sql_mode if already set.
删除STRICT_TRANS_TABLE从global sql_mode
。你可能需要的其他属性,如NO_ZERO_DATE如果已经设置在全球的sql_mode。
Set this under [mysqld] in my.cnf (or /etc/mysql/mysql.conf.d/mysqld.cnf) depending on your server version.
根据您的服务器版本,在 my.cnf(或 /etc/mysql/mysql.conf.d/mysqld.cnf)中的 [mysqld] 下设置此项。
[mysqld]
sql_mode = "NO_ZERO_IN_DATE,NO_ZERO_DATE,ERROR_FOR_DIVISION_BY_ZERO,NO_AUTO_CREATE_USER,NO_ENGINE_SUBSTITUTION"