0

我正在将数据从 a 导入csvMySQL表中。我需要将日期格式从转换StringDate. 从开始格式到结束格式:

Mon Feb 04 00:00:00 UTC 2011  ---> 2011-02-04 00:00:00

我已经成功地做到了:

select str_to_date('Mon Feb 04 00:00:00 UTC 2011', '%a %b %d %k:%i:%s UTC %Y');

现在我正在编写脚本来执行从 中的所有导入csv,有 2 列带有要转换的日期,但我遇到了MySQL语法异常set

我的SQL脚本:

load data local infile 'movimento.csv' into table movimento
fields terminated by ',' lines terminated by '\n'
(id, anno, creditore, @data_pag, @data_spost, descrizione)
set data_pagamento = str_to_date(@data_pag, '%a %b %d %k:%i:%s UTC %Y')
set data_spostamento = str_to_date(@data_spost, '%a %b %d %k:%i:%s UTC %Y')
show warnings;

我遇到了语法异常set。错误:

ERROR 1064 (42000):您的 SQL 语法有错误;检查与您的 MySQL 服务器版本相对应的手册,以在 'set data_spostamento = str_to_date(@data_spost, '%a %b %d %k:%i:%s UTC %Y') show' 行附近使用正确的语法5 >

什么是正确的语法?

4

1 回答 1

2

语法不正确。试试这个——

LOAD DATA LOCAL INFILE 'movimento.csv' INTO TABLE movimento
FIELDS TERMINATED BY ',' LINES TERMINATED BY '\n'
(ID, anno, creditore, @data_pag, @data_spost, descrizione)
SET
  data_pagamento = STR_TO_DATE(@data_pag, '%a %b %d %k:%i:%s UTC %Y'),
  data_spostamento = STR_TO_DATE(@data_spost, '%a %b %d %k:%i:%s UTC %Y')
于 2013-03-28T11:20:44.013 回答