[英]Oracle comparing timestamp with date
I have a timestamp field and I just want to compare the date part of it in my query in Oracle 我有一个时间戳字段,我只想在Oracle的查询中比较它的日期部分
How do I do that, 我怎么做,
SELECT *
FROM Table1
WHERE date(field1) = '2012-01-01'
You can truncate the date part: 您可以截断日期部分:
select * from table1 where trunc(field1) = to_date('2012-01-01', 'YYYY-MM-DD')
The trouble with this approach is that any index on field1
wouldn't be used due to the function call. 这种方法的问题在于,由于函数调用,不会使用
field1
上的任何索引。
Alternatively (and more index friendly) 或者(更多索引友好)
select * from table1
where field1 >= to_timestamp('2012-01-01', 'YYYY-MM-DD')
and field1 < to_timestamp('2012-01-02', 'YYYY-MM-DD')
You can truncate the date 您可以截断日期
SELECT *
FROM Table1
WHERE trunc(field1) = to_Date('2012-01-01','YYY-MM-DD')
Look at the SQL Fiddle for more examples. 有关更多示例,请查看SQL Fiddle 。
to_date
format worked for me. to_date
格式对我to_date
。 Please consider the date formats: MON-
, MM
, .
请考虑日期格式:
MON-
, MM
, .
, -
. ,
-
。
t.start_date >= to_date('14.11.2016 04:01:39', 'DD.MM.YYYY HH24:MI:SS')
t.start_date <=to_date('14.11.2016 04:10:07', 'DD.MM.YYYY HH24:MI:SS')
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.