ERROR 1292 (22007): Incorrect datetime value: '' for column 'end_date' at row 1

mysql使用load data infile出现如下错误:

root@NoName 21:35:44> load data infile '/company.csv'  into table  company CHARACTER SET utf8 fields terminated by ',' optionally enclosed by '"' escaped by '"' 

    -> (src_company_id,company_name,province,start_date,econ_kind,oper_name,raw_regist_capi,regist_capi,

regist_capi_desc,cur_type,regist_no,credit_code,org_no,address,scope,term_start,term_end,belong_org,

check_date,end_date,status,is_listed,is_NEEQ,is_expired,main_category,big_category,src_created_date,

src_updated_date)

    -> ;
ERROR 1292 (22007): Incorrect datetime value: '' for column 'end_date' at row 1


这里的原因在于,end_date这个字段在csv文件中是空值。如果表中对应的字段允许为空的话,就可以按照下面的方式处理:注意上色的。

load data infile '/company.csv'  into table  company CHARACTER SET utf8 fields terminated by ',' optionally enclosed by '"' escaped by '"' 
(src_company_id,company_name,province,start_date,econ_kind,oper_name,raw_regist_capi,regist_capi,

regist_capi_desc,cur_type,regist_no,credit_code,org_no,address,scope,term_start,term_end,belong_org,

check_date,@end_date1,status,is_listed,is_NEEQ,is_expired,main_category,big_category,

src_created_date,src_updated_date)

set end_date=if(@end_date1='',NULL,  @end_date1);

猜你喜欢

转载自blog.csdn.net/w1346561235/article/details/74502886