如何将时间戳从 Oracle 转换为 Mysql
How to convert timestamp from Oracle to Mysql
我正在尝试将时间戳从 Oracle 转换为 Mysql。我有一个数据文本文件,试图在 MySQL 数据库中加载数据,但出现 SQL 语法错误。请帮忙
LOAD DATA INFILE '/check/value.txt' INTO TABLE TEST FIELDS TERMINATED BY '|' (ID, @DATETIME) SET DATETIME = CONVERT_TZ(REPLACE(SUBSTRING_INDEX(@DATETIME, '-', 3),"T"," "), "-07:00", "+00:00");
时间戳示例 - 2020-10-07T05:21:05-7:00。
错误如下
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET DATETIME = CONVERT_TZ(REPLACE(SUBSTRING_INDEX(@DATETIME, '-', 3),"T"," "), "-07:00", "+00:00")'
你可以试试这个:
SELECT CONVERT_TZ(REPLACE(SUBSTRING_INDEX("2020-10-07T05:21:05-7:00", '-', 3),"T"," "), "-07:00", "+00:00");
SET @time := '2020-10-07T05:21:05-7:00';
SELECT CONVERT_TZ(STR_TO_DATE( @time, '%Y-%m-%dT%H:%i:%s'), -- datetime only
REGEXP_SUBSTR(@time, '[\+\-][0-9]{1,2}:[0-9]{2}$'), -- timeshift only
'+00:00') AS datetime_GMT;
我正在尝试将时间戳从 Oracle 转换为 Mysql。我有一个数据文本文件,试图在 MySQL 数据库中加载数据,但出现 SQL 语法错误。请帮忙
LOAD DATA INFILE '/check/value.txt' INTO TABLE TEST FIELDS TERMINATED BY '|' (ID, @DATETIME) SET DATETIME = CONVERT_TZ(REPLACE(SUBSTRING_INDEX(@DATETIME, '-', 3),"T"," "), "-07:00", "+00:00");
时间戳示例 - 2020-10-07T05:21:05-7:00。
错误如下
ERROR 1064 (42000): You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'SET DATETIME = CONVERT_TZ(REPLACE(SUBSTRING_INDEX(@DATETIME, '-', 3),"T"," "), "-07:00", "+00:00")'
你可以试试这个:
SELECT CONVERT_TZ(REPLACE(SUBSTRING_INDEX("2020-10-07T05:21:05-7:00", '-', 3),"T"," "), "-07:00", "+00:00");
SET @time := '2020-10-07T05:21:05-7:00';
SELECT CONVERT_TZ(STR_TO_DATE( @time, '%Y-%m-%dT%H:%i:%s'), -- datetime only
REGEXP_SUBSTR(@time, '[\+\-][0-9]{1,2}:[0-9]{2}$'), -- timeshift only
'+00:00') AS datetime_GMT;