oracle-databaseto-date

String to date in Oracle with milliseconds


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/SQL keep throwing this error:

ORA-01821: date format not recognized.

FF9 is incorrect for Oracle, any suggestion?


Solution

  • 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