MySQL 1292:日期时间值不正确:“TERM_DATE”列的第 1 行
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/28530195/
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
1292: Incorrect datetime value: '' for column 'TERM_DATE' at row 1
提问by Mithun Raj
I am trying to load data from excel sheet to the below table on MYSQL 5.6 on windows 8.1 and I am getting 'Incorrect datetime value:' error.
我试图在 Windows 8.1 上的 MYSQL 5.6 上将 Excel 工作表中的数据加载到下表中,但出现“日期时间值不正确:”错误。
Term date column is of DATETIME data type and the data has null values in the excel sheet which I am trying to insert into the table.
术语日期列是 DATETIME 数据类型,数据在我试图插入表中的 Excel 工作表中具有空值。
I did some research and found that the problem is with the SQL strict mode. But I am not able to figure out how to disable or modify the SQL strict mode.
我做了一些研究,发现问题出在 SQL 严格模式上。但我无法弄清楚如何禁用或修改 SQL 严格模式。
I in fact tried this SET SESSION sql_mode='ALLOW_INVALID_DATES'
but no luck.
事实上,我试过这个,SET SESSION sql_mode='ALLOW_INVALID_DATES'
但没有运气。
Some said editing my.ini file in installation directory will help but I am not able to find it in the installation directory.
有人说在安装目录中编辑 my.ini 文件会有所帮助,但我在安装目录中找不到它。
can any one please help me resolve this issue.
任何人都可以帮我解决这个问题。
create table EMPLOYEE(EMP_ID integer(10),
EMP_NAME char(25),
SALARY integer(25),
START_DATE datetime,
TERM_DATE datetime DEFAULT '1900-01-01',
PRIMARY KEY (EMP_ID));
Error Message:
错误信息:
15:23:08 INSERT INTO `mith`.`EMPLOYEE` (`EMP_ID`, `EMP_NAME`, `SALARY`, `START_DATE`, `TERM_DATE`) VALUES ('26', 'Will Banker', '90000', '00:00.0', '') 1292: Incorrect datetime value: '' for column 'TERM_DATE' at row 1
回答by Mureinik
In MySQL, ''
(an empty string) is different from a null
. If you want a null
value, you should use an explicit null
:
在 MySQL 中,''
(空字符串)不同于null
. 如果你想要一个null
值,你应该使用一个显式的null
:
INSERT INTO `mith`.`EMPLOYEE`
(`EMP_ID`, `EMP_NAME`, `SALARY`, `START_DATE`, `TERM_DATE`)
VALUES ('26', 'Will Banker', '90000', '00:00.0', null)
回答by Marcos Roberto Silva
I managed to solve a similar problem using the commands:
我设法使用以下命令解决了类似的问题:
mysql> set session sql_mode='';
and
和
mysql> set global sql_mode='';
in mysql prompt.
在 mysql 提示符下。
回答by Joachim
Try replacing the null values in Excel with 0000-00-00. I have not tried this with Excel, but it works for csv file. import
尝试用 0000-00-00 替换 Excel 中的空值。我没有用 Excel 尝试过这个,但它适用于 csv 文件。进口