Oracle-数据类型为date 日期查询技巧
在Oracle中查询Date类型字段的数据
date是注意格式的数据类型。注意
在保存的时候会自带时分秒;
例:‘yyyyMMdd’;'yyyy-mm-dd hh24:mi’等;
可以使用to_char函数将其转化为任意时间格式的字符串,也可使用to_date函数转化相应的字符串为日期格式。
我这里使用的to_char函数。
方式一:
select * from [表名] where to_char([需要查询的字段],'yyyyMMdd') between '20200601' and '20200630'
select * from student where to_char(studate,'yyyMMdd')
between '20200601' and '20200630'
方式二:
select * from [表名] where [需要查询的字段] between to_date('20200601', 'yyyy-mm-dd hh24:mi') and to_date('20200630', 'yyyy-mm-dd hh24:mi')
select * from student where studate between to_char(20200601,'yyyMMdd') and
to_char(20200630,'yyyMMdd')
本文介绍在Oracle数据库中如何使用to_char和to_date函数查询特定日期范围内的数据,提供了两种实用的查询方式,帮助读者掌握更高效的日期数据检索方法。
423

被折叠的 条评论
为什么被折叠?



