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')