Mysql将'CYYMM'转换为'YYMM'

时间:2013-12-13 14:31:04

标签: mysql sql date load-data-infile date-conversion

吮吸以下内容:

$loaddata = "LOAD DATA INFILE 'filename.csv' 
    INTO TABLE tb1
    FIELDS TERMINATED BY ','
    LINES TERMINATED BY '\\r\\n'
    IGNORE 1 LINES
    (
    Entity,
    HK,
    @Period,
    )
    SET Period = STR_TO_DATE(@Period,'%C%YY%MM')
    ";

附近给出了我和sql语法错误
 ) SET Period = STR_TO_DATE(@Period,'%C%YY%MM')

Period是DATE变量。在10月13日期间,cvs将显示11310。

事先提前!

1 个答案:

答案 0 :(得分:1)

@Period之后你有一个多余的逗号:

$loaddata = "LOAD DATA INFILE 'filename.csv' 
    INTO TABLE tb1
    FIELDS TERMINATED BY ','
    LINES TERMINATED BY '\\r\\n'
    IGNORE 1 LINES
    (
    Entity,
    HK,
    @Period -- , removed here
    )
    SET Period = STR_TO_DATE(@Period,'%C%YY%MM')
    ";

但是,您的日期格式字符串几乎肯定是不正确的。 %C%YY%MM是无效的说明符。请参阅DATE_FORMAT()