码迷,mamicode.com
首页 > 数据库 > 详细

oracle日期时间范围查询

时间:2017-04-07 20:34:38      阅读:286      评论:0      收藏:0      [点我收藏+]

标签:logs   code   where   create   类型   data   href   bsp   tar   

Oracle的日期时间范围查询

字段为:字符串类型(char),长度为:10

SELECT * FROM testdatetime t WHERE 1=1 AND t.createdate >= 2011-06-01 AND t.createdate <= 2011-07-05;

SELECT * FROM testdatetime t WHERE 1=1 AND to_date(t.createdate,‘yyyy-MM-dd‘)
between to_date(‘2011-06-01‘,‘yyyy-MM-dd‘) and to_date(‘20110705‘,‘yyyymmdd‘) ; 

字段为:字符串类型(char),长度为:20 

SELECT * FROM testdatetime t WHERE 1=1 AND t.usedate >= 2011-06-01 AND t.usedate <= 2011-07-05;  
  
SELECT * FROM testdatetime t WHERE 1=1 AND to_date(t.usedate,yyyy-MM-dd HH24:MI:SS)
between to_date(2011-07-01 12:00:00,yyyy-MM-dd HH24:MI:SS) and to_date(20110702 12:00:00,yyyymmdd HH24:MI:SS) ;  

字段为:日期时间类型(date)

SELECT * FROM testdatetime t WHERE 1=1 AND t.startdate >= to_date(2011-07-01,yyyy-MM-dd) AND t.startdate <= to_date(2011-07-02,yyyy-MM-dd);  
SELECT * FROM testdatetime t WHERE 1=1 AND t.startdate between to_date(2011-07-01,yyyy-MM-dd) AND to_date(2011-07-02,yyyy-MM-dd); 
SELECT * FROM testdatetime t WHERE 1=1 AND t.startdate = to_date(‘2011-07-01 12:00:00‘,‘yyyy-MM-dd HH24:MI:SS‘); 
SELECT * FROM testdatetime t WHERE 1=1 AND to_char(t.startdate,‘yyyy-MM-dd‘) = ‘2011-07-01‘;
SELECT * FROM testdatetime t WHERE 1=1 AND to_char(t.startdate,‘yyyy-MM-dd‘) >= ‘2011-07-01‘ AND to_char(t.startdate,‘yyyy-MM-dd‘) <= ‘2011-07-02‘;  

 

oracle日期时间范围查询

标签:logs   code   where   create   类型   data   href   bsp   tar   

原文地址:http://www.cnblogs.com/daduryi/p/6679433.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!