我正在将数据从 a 导入csv到MySQL表中。我需要将日期格式从转换String为Date. 从开始格式到结束格式:
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 >
什么是正确的语法?