• 首页 首页 icon
  • 工具库 工具库 icon
    • IP查询 IP查询 icon
  • 内容库 内容库 icon
    • 快讯库 快讯库 icon
    • 精品库 精品库 icon
    • 问答库 问答库 icon
  • 更多 更多 icon
    • 服务条款 服务条款 icon

oracle查看询大于指定时间的数据

武飞扬头像
PHP中文网
帮助43

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 这一时刻的记录也包括在内啦!

这篇好文章是转载于:学新通技术网

  • 版权申明: 本站部分内容来自互联网,仅供学习及演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,请提供相关证据及您的身份证明,我们将在收到邮件后48小时内删除。
  • 本站站名: 学新通技术网
  • 本文地址: /boutique/detail/tanfigac
系列文章
更多 icon
同类精品
更多 icon
继续加载