在 Oracle 中将 VARCHAR2 转换为 TIMESTAMP
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7606903/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Convert VARCHAR2 to TIMESTAMP in Oracle
提问by Bathiya Priyadarshana
I have a VARCHAR2 value in the format '14-SEP-11 12.33.48.537150 AM' and I need to convert this to a TIMESTAMP as is. That is like,
我有一个格式为“14-SEP-11 12.33.48.537150 AM”的 VARCHAR2 值,我需要将其按原样转换为 TIMESTAMP。那就像,
SELECT TO_DATE('14-SEP-11 12.33.48.537150 AM', '<format_string>') FROM DUAL;
I want the return from the above query to be '14-SEP-11 12.33.48.537150 AM' in TIMESTAMP data format.
我希望上述查询的返回值为 TIMESTAMP 数据格式的“14-SEP-11 12.33.48.537150 AM”。
What should be the 'format_string' for this.
'format_string' 应该是什么。
Please help since I tried many things but none works.. :(
请帮忙,因为我尝试了很多东西,但都没有奏效.. :(
I am using Oracle 11gR2.
我正在使用 Oracle 11gR2。
Thanks.
谢谢。
回答by APC
DATE and TIMESTAMP are two different datatypes. So you need to use the correct conversion function for each, which in your case would be TO_TIMESTAMP().
DATE 和 TIMESTAMP 是两种不同的数据类型。所以你需要为每个使用正确的转换函数,在你的情况下是TO_TIMESTAMP()。
SELECT TO_TIMESTAMP('14-SEP-11 12.33.48.537150 AM', 'DD-MON-RR HH:MI:SS.FF AM')
FROM DUAL;
回答by gpeche
select from_tz(to_timestamp('14-SEP-11 12.33.48.537150 PM', 'DD-Mon-RR HH.MI.SS.FF AM'), 'EUROPE/LONDON') from dual