Oracle - Fetch date/time in milliseconds from DATE datatype field

后端 未结 3 1415
梦毁少年i
梦毁少年i 2021-01-13 15:39

I have last_update_date column defined as DATE field

I want to get time in milliseconds.

Currently I have:

TO_CHAR         


        
相关标签:
3条回答
  • 2021-01-13 15:54

    As RC says, the DATE type only supports a granularity down to the second.

    If converting to TIMESTAMP is truly not an option then how about the addition of another numerical column that just holds the milliseconds?

    This option would be more cumbersome to deal with than a TIMESTAMP column but it could be workable if converting the type is not possible.

    0 讨论(0)
  • 2021-01-13 16:01

    In a similar situation where I couldn't change the fields in a table, (Couldn't afford to 'break' third party software,) but needed sub-second precision, I added a 1:1 supplemental table, and an after insert trigger on the original table to post the timestamp into the supplemental table.

    If you only need to know the ORDER of records being added within the same second, you could do the same thing, only using a sequence as a data source for the supplemental field.

    0 讨论(0)
  • 2021-01-13 16:05

    DATE fields on Oracle only store the data down to a second so there is no way to provide anything more precise than that. If you want more precision, you must use another type such as TIMESTAMP.

    Here is a link to another SO question regarding Oracle date and time precision.

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