SQL子句中有以下内容。这是针对Oracle数据库运行的。时间戳字段在数据库中被定义为Time估值字段。我的选择查询是:
create index ind_timestamp on sms_in(to_char(timestamp,'YYYY-MM-DD'));
select * from sms_in where to_char(timestamp,'YYYY-MM-DD')in '2018-08-01';但是,当我要执行查询时,数据库访问是满的。这意味着索引不起作用。
发布于 2018-08-07 12:55:21
如果你总是在寻找某一天的数据,那么我的建议如下
在timestamp列上添加一个普通索引
create index ind_timestamp on sms_in(timestamp);你的选择看起来就像
select *
from sms_in
where timestamp between to_date('2018-08-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
and to_date('2018-08-01 23:59:59','YYYY-MM-DD HH24:MI:SS');或者你可以这样做
select *
from sms_in
where timestamp >= to_date('2018-08-01 00:00:00', 'YYYY-MM-DD HH24:MI:SS')
and timestamp <= to_date('2018-08-01 23:59:59','YYYY-MM-DD HH24:MI:SS');编辑:
这个答案基本上是正确的,但逻辑应该是:
select *
from sms_in
where timestamp >= date '2018-08-01' and
timestamp < date '2018-08-02 ;https://stackoverflow.com/questions/51726769
复制相似问题