[英]How to convert string to date format in Oracle
I have a file contains a string like 2011-03-14 11:57:42+08:00
and I need to store it in a column with DATE
datatype. 我有一个文件,其中包含类似于2011-03-14 11:57:42+08:00
的字符串,我需要将其存储在具有DATE
数据类型的列中。 I use Oracle 11g. 我使用Oracle 11g。
I have tried TO_DATE
function but it didn't work. 我已经尝试过TO_DATE
函数,但是没有用。
Can anyone help me? 谁能帮我?
thanks in advance 提前致谢
You have to use the function TO_TIMESTAMP_TZ
to get the timezone properly parsed: 您必须使用函数TO_TIMESTAMP_TZ
来正确解析时区:
SELECT CAST(TO_TIMESTAMP_TZ('2011-03-14 11:57:42+08:00', 'YYYY-MM-DD HH24:MI:SS+TZH:TZM') AS DATE) AS my_date
FROM DUAL
;
(And as a side note to your example in the comment: no need for TO_CHAR
, quoting was missing and format model MON
(abbreviated month) was incorrect) (作为注释中您的示例的附带说明:不需要TO_CHAR
,引号丢失并且格式模型MON
(缩写月份)不正确)
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.