在oracle中,可利用select语句配合“to_date”函数查询大于指定时间的数据,语法为“select * from 表名 where 列名 to_date(指定时间格式,yyyy-mm-dd hh24:mi:ss)”。 本教程操作环境:Windows10系统、
在oracle中,可利用select语句配合“to_date”函数查询大于指定时间的数据,语法为“select * from 表名 where 列名 > to_date(‘指定时间格式’,’yyyy-mm-dd hh24:mi:ss’)”。

本教程操作环境:Windows10系统、Oracle 11g版、Dell G3电脑。
oracle怎么查询大于指定时间的数据
查询的结果,要求某列大于某个时间点的记录。
— tablename 表名
— columnname 列名
select * from tablename where columnname > to_date(‘2022:5:25 09:40:00′,’yyyy-mm-dd hh24:mi:ss’);
示例如下:

modifytime 和 create 都是字符串,需要转成时间,时间和时间比较;不然会提示文字和字符不匹配。
扩展知识:
例如:我要查一张表 2011年3月11日到2011年3月24日内所生成的数据,其区间应该为[2011-03-11 00:00:00, 2011-03-25 00:00:00)
— 即:不包括右边2011-03-25 00:00:00时间点的值!
— 所以,请看如下:

— 查看2011年24日生成的数据
— 方法一:用 … and …
eygle@SZTYORA> select count(*) from t
2 where cdate>=to_date(‘2011-03-24′,’yyyy-mm-dd’)
3 and cdate
COUNT(*)
———-
5
— 方法二:用between … and …
eygle@SZTYORA> select count(*) from t
2 where cdate between to_date(‘2011-03-24′,’yyyy-mm-dd’)
3 and to_date(‘2011-03-25′,’yyyy-mm-dd’);
COUNT(*)
———-
6
eygle@SZTYORA> select * from t
2 where cdate between to_date(‘2011-03-24′,’yyyy-mm-dd’)
3 and to_date(‘2011-03-25′,’yyyy-mm-dd’)
4 order by cdate;
CDATE
——————-
2011-03-24 00:00:00
2011-03-24 02:03:45
2011-03-24 10:37:03
2011-03-24 20:55:17
2011-03-24 23:59:59
2011-03-25 00:00:00
已选择6行。
— 可见方法二用between … and … 是错误的,它将2011-03-25 00:00:00 这一时刻的记录也包括在内啦!
推荐教程:《Oracle视频教程》
以上就是oracle怎么查询大于指定时间的数据的详细内容,更多请关注每日运维其它相关文章!



