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);

  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值