27

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?

Luixv
  • 7,860
  • 18
  • 77
  • 118
Custodio
  • 7,430
  • 12
  • 75
  • 110

2 Answers2

67

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
Quassnoi
  • 381,935
  • 83
  • 584
  • 593
  • Datetime Format Elements: https://docs.oracle.com/cd/B19306_01/server.102/b14200/sql_elements004.htm#i34924 – Vadzim Nov 08 '18 at 13:36
4

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.

Jeremy Bourque
  • 3,383
  • 1
  • 19
  • 18