Using Oracle to_date function for date string with milliseconds

前端 未结 5 465
自闭症患者
自闭症患者 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:31

    For three digits millisecond:

    TO_CHAR(LN_AUTOD_UWRG_DTTM,'MM/DD/YYYY HH24:MI:SS.FF3')
    

    For six digits millisecond:

    TO_CHAR(LN_AUTOD_UWRG_DTTM,'MM/DD/YYYY HH24:MI:SS.FF'),
    
    0 讨论(0)
  • 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' )
    
    0 讨论(0)
  • 2020-12-08 09:45

    You can try this format SS.FF for milliseconds:

    to_timestamp(table_1.date_col,'DD-Mon-RR HH24:MI:SS.FF')

    For more details:
    https://docs.oracle.com/cd/B19306_01/server.102/b14200/functions193.htm

    0 讨论(0)
  • 2020-12-08 09:48

    You have to change date class to timestamp.

    String s=df.format(c.getTime());
    java.util.Date parsedUtilDate = df.parse(s);  
    java.sql.Timestamp timestamp = new java.sql.Timestamp(parsedUtilDate.getTime());
    
    0 讨论(0)
  • 2020-12-08 09:49

    TO_DATE supports conversion to DATE datatype, which doesn't support milliseconds. If you want millisecond support in Oracle, you should look at TIMESTAMP datatype and TO_TIMESTAMP function.

    Hope that helps.

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