在 Oracle 中以毫秒为单位的字符串
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/1758219/
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
String to date in Oracle with milliseconds
提问by Custodio
I want to convert the follow string to date:
我想将以下字符串转换为日期:
2004-09-30 23:53:48,140000000
I tried:
我试过:
to_date('#', 'YYYY-MM-DD HH24:MI:SS,FF9')
But PL/SQLkeep throwing this error:
但是PL/SQL不断抛出这个错误:
ORA-01821: date format not recognized.
FF9 is incorrect for Oracle, any suggestion?
FF9 对 Oracle 不正确,有什么建议吗?
回答by Quassnoi
Oracle
stores only the fractions up to second in a DATE
field.
Oracle
在一个DATE
字段中只存储最高达秒的分数。
Use TIMESTAMP
instead:
使用TIMESTAMP
来代替:
SELECT TO_TIMESTAMP('2004-09-30 23:53:48,140000000', 'YYYY-MM-DD HH24:MI:SS,FF9')
FROM dual
, possibly casting it to a DATE
then:
,可能将其强制转换为DATE
then:
SELECT CAST(TO_TIMESTAMP('2004-09-30 23:53:48,140000000', 'YYYY-MM-DD HH24:MI:SS,FF9') AS DATE)
FROM dual
回答by Jeremy Bourque
I don't think you can use fractional seconds with to_date or the DATE type in Oracle. I think you need to_timestamp which returns a TIMESTAMP type.
我认为您不能在 Oracle 中对 to_date 或 DATE 类型使用小数秒。我认为你需要 to_timestamp 返回一个 TIMESTAMP 类型。