sql--oracle 按时间查询

Posted on 2017-12-15 10:10  我世界里的悲伤  阅读(3021)  评论(0)    收藏  举报

根据时间在表中  数据结构 查询的方式不同

create table MyTest {

  ID   Int  not null  primary KEY,

  createDate   String null,

  startDate  date null,

  endDate  date null,

  buyDate char(10)  null,

  useDate varchar2(20) null,

}

1、字段为字符串类型:可以直接查询,和字符串进行比较。

  select  * from  MyTest a where a.createDate = '2017-12-15';

2、字段为 date :可以转化为字符串进行查询,和相同类型进行比较。

  select * from MyTest a where a.startDate < to_date('2017-12-15','yyyy-MM-dd');

  select * from MyTest a where a.startDate < to_date('2017-12-15 12:12:12','yyyy-MM-dd HH24:MI:SS');

  select * from MyTest a where to_char(a.createDate,'yyyy-MM-dd') > '2017-12-15';

  select to_char(a.startDate:'yyyy-MM-dd HH24:MI:SS') from MyTest a where to_date('2017-12-12':'yyyy-MM-dd') < = a.endDate;