简体   繁体   中英

Oracle Convert Char to Date

I have the following date in oracle table:

'2017-08-01 00:00:00,000000000'

I want to convert this to date which I am using the following but I don't know how to deal with zeroes?!

.
.
.
T.EXECUTION_LOCAL_DATE_TIME
between to_date('2017-08-01  00:00:00,000000000', 'yyyy-mm-dd hh:mi:ss')
and to_date('2017-08-10 00:00:00,000000000', 'yyyy-mm-dd  hh:mi:ss');

Could anyone help me with this?

Oracle dates do not support milliseconds. Assuming your EXECUTION_LOCAL_DATE_TIME column is a date, then the following comparison is the best you can do:

T.EXECUTION_LOCAL_DATE_TIME
BETWEEN TO_DATE('2017-08-01 00:00:00', 'yyyy-mm-dd hh:mi:ss') AND
        TO_DATE('2017-08-10 00:00:00', 'yyyy-mm-dd hh:mi:ss');

If you wanted to convert a text string with milliseconds to a timestamp, you could use something like this:

TO_TIMESTAMP ('2017-08-01 00:00:00,000000000', 'yyyy-mm-dd hh:mi:ss,ff')

Generally speaking this values in not a date but a timestamp so I would use following conversion:

select to_timestamp('2017-08-01 00:00:00,000000000', 'yyyy-mm-dd hh24:mi:ss,ff6')
from dual;

Technically you can have non zeros after comma, so If you want to get correct but not truncated value use timestamp date type.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM