oracle怎么查詢大于指定時間的數據

oracle中,可利用select語句配合“to_date”函數查詢大于指定時間的數據,語法為“select * from 表名 where 列名 > to_date(‘指定時間格式’,’yyyy-mm-dd hh24:mi:ss’)”。

oracle怎么查詢大于指定時間的數據

本教程操作環境: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');

示例如下:

oracle怎么查詢大于指定時間的數據

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時間點的值!

— 所以,請看如下:

oracle怎么查詢大于指定時間的數據

— 查看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視頻教程

以上就是

? 版權聲明
THE END
喜歡就支持一下吧
點贊12 分享