欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页  >  IT编程

mysql使用load data infile出现错误

程序员文章站 2022-08-06 21:32:59
mysql使用load data infile出现错误 mysql使用load data infile出现如下错误: root@noname 21:35:44> load...

mysql使用load data infile出现错误

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