Oracle模糊查询时间以及按照时间区间查询+补充mysql

来源:互联网 发布:桌面录制视频软件 编辑:程序博客网 时间:2024/06/06 20:02

Oracle模糊查询时间


select * from 表明  where to_char(列名,'yyyy-mm-dd HH')='2015-10-15 12';


Oracle模糊查询到时、分、秒---"LIKE"和"="的效果是一样的:注意是yyyy-mm-dd hh24: mi:ss

select * from 表名 t where to_char(时间字段'yyyy-mm-dd hh24:mi:ss') like '2015-11-05 17:11' ;

select * from 表名 t where to_char(时间字段'yyyy-mm-dd hh24:mi:ss') = '2015-11-05 17:11' ;


yyyy-mm-dd hh24: mi:ss 可以自由组合

yyyy-mm-dd   2015-11-05 

yyyy-mm-dd hh24   2015-11-05 17

yyyy-mm-dd hh24: mi 2015-11-05 17:11

yyyy-mm-dd hh24: mi:ss  2015-11-05 17:11:20



按照时间区间查询

select * from 表名 bnm where bnm.date >= to_date('2016-03-04','yyyy-mm-dd') and bnm.date <= to_date('2016-03-27','yyyy-mm-dd')


按照具体到秒数

select * from 表名 bnm where bnm.date >= to_date('2016-04-01 10:01:01','yyyy-mm-dd hh:mi:ss')


24小时

to_date('2016-05-27 17:00:00','yyyy-MM-dd hh24:mi:ss')



后期补充-转自-http://ducaijun.iteye.com/blog/1768836

对于mysql

 

mysql日期和字符相互转换方法

date_format(date,'%Y-%m-%d')    -------------->oracle中的to_char();

str_to_date(date,'%Y-%m-%d')     -------------->oracle中的to_date();

 

%Y:代表4位的年份

%y:代表2为的年份

 

%m:代表月, 格式为(01……12)  

%c:代表月, 格式为(1……12)

 

%d:代表月份中的天数,格式为(00……31)  

%e:代表月份中的天数, 格式为(0……31) 

 

%H:代表小时,格式为(00……23)  

%k:代表 小时,格式为(0……23)  

%h: 代表小时,格式为(01……12)  

%I: 代表小时,格式为(01……12)  

%l :代表小时,格式为(1……12)

 

%i: 代表分钟, 格式为(00……59) 

 

%r:代表 时间,格式为12 小时(hh:mm:ss [AP]M)  

%T:代表 时间,格式为24 小时(hh:mm:ss) 

 

%S:代表 秒,格式为(00……59)  

%s:代表 秒,格式为(00……59) 

 

 

 

SELECT DATE_FORMAT(20130111191640,'%Y-%m-%d %H:%i:%s')

 

 

DATE_FORMAT(20130111191640,'%Y-%m-%d %H:%i:%s')

-----------------------------------------------

2013-01-11 19:16:40         


0 0
原创粉丝点击