简体   繁体   English

Oracle将字符转换为日期

[英]Oracle Convert Char to Date

I have the following date in oracle table: 我在oracle表中有以下日期:

'2017-08-01 00:00:00,000000000' '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. Oracle日期不支持毫秒。 Assuming your EXECUTION_LOCAL_DATE_TIME column is a date, then the following comparison is the best you can do: 假设您的EXECUTION_LOCAL_DATE_TIME列是一个日期,那么以下比较是您可以做的最好的事情:

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. 从技术上讲,逗号后可以有非零值,因此,如果要获取正确但不被截断的值,请使用时间戳记日期类型。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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