LOAD DATA INFILE使用STR_TO_DATE转换2个日期(@ var1,'%m /%d /%Y') - 抛出错误

时间:2012-11-08 01:10:46

标签: mysql

这是一个错误,我无法弄清楚为什么,任何想法?

LOAD DATA LOCAL INFILE 'H:/Data/DB__Muni/data/msrb_AZ_short1.csv'
INTO TABLE import_mdrp FIELDS TERMINATED BY ';' LINES TERMINATED BY '\r\n' 
  ( 
    Issuer, cusip6, state, Issue,
    page_pointer, @var1, date_rng, cusip9, @var2,
    yield, Amt_Offer_Dlr, Amt_Offer_Per, Security_Description,
    Fitch, Moody, cusip_img, fitch_img, moody_img 
  )
SET maturity = STR_TO_DATE(@var2,'%m/%d/%Y') 
SET issue_date = STR_TO_DATE(@var1,'%m/%d/%Y') 
;

1 个答案:

答案 0 :(得分:6)

而不是

SET maturity = STR_TO_DATE(@var2,'%m/%d/%Y') 
SET issue_date = STR_TO_DATE(@var1,'%m/%d/%Y') 

SET maturity = STR_TO_DATE(@var2,'%Y-%m-%d') 
SET issue_date = STR_TO_DATE(@var1,'%Y-%m-%d') 

更新1

SET maturity = DATE_FORMAT(STR_TO_DATE(@var2, '%m/%d/%Y'), '%Y-%m-%d'),
    issue_date = DATE_FORMAT(STR_TO_DATE(@var1, '%m/%d/%Y'), '%Y-%m-%d')