Using Oracle to_date function for date string with milliseconds

前端 未结 5 477
自闭症患者
自闭症患者 2020-12-08 09:00

I have to perform some inserts into an Oracle DB. I have some dates in the following format

\'23.12.2011 13:01:001\'

Following the documen

5条回答
  •  无人及你
    2020-12-08 09:32

    An Oracle DATE does not store times with more precision than a second. You cannot store millisecond precision data in a DATE column.

    Your two options are to either truncate the string of the milliseconds before converting it into a DATE, i.e.

    to_date( substr('23.12.2011 13:01:001', 1, 19), 'DD.MM.YYYY HH24:MI:SS' )
    

    or to convert the string into a TIMESTAMP that does support millisecond precision

    to_timestamp( '23.12.2011 13:01:001', 'DD.MM.YYYY HH24:MI:SSFF3' )
    

提交回复
热议问题