1、查询某天数据
方式一:最快(前提是:时间字段建立了索引,此语句按索引查询)
select * from special_maintain where create_time>=trunc(to_date('20170428','yyyy-MM-dd')) and create_time<trunc(to_date('20170428','yyyy-MM-dd')+1);
special_maintain:表名,create_time:时间字段、Date类型
创建索引语句是:create indexspecial_maintain_create_idx on special_maintain(create_time);
方式二:trunc 不可具体到 小时、分钟
select * from special_maintain where trunc(create_time)=trunc(to_date('20170428','yyyy-MM-dd'));
方式三:to_char
select * from special_maintain where to_char(create_time,'yyyy-MM-dd')='2017-04-28';
也可用具体到 小时、分钟
select * from special_maintain where to_char(create_time,'yyyy-MM-dd hh:mi')='2017-04-28 11:05';