String to date in Oracle with milliseconds

前端 未结 2 1196
我在风中等你
我在风中等你 2020-12-01 09:45

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,         


        
相关标签:
2条回答
  • 2020-12-01 10:04

    Oracle stores only the fractions up to second in a DATE field.

    Use TIMESTAMP instead:

    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:

    SELECT  CAST(TO_TIMESTAMP('2004-09-30 23:53:48,140000000', 'YYYY-MM-DD HH24:MI:SS,FF9') AS DATE)
    FROM    dual
    
    0 讨论(0)
  • 2020-12-01 10:06

    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.

    0 讨论(0)
提交回复
热议问题