Oracle資料庫比較日期時間的大小

2021-10-12 02:51:51 字數 3196 閱讀 5173

在今天或者今天之前作比較:

select * from jn_bus_kjlwsbjbxx where dqsj < to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

select * from jn_bus_kjlwsbjbxx where dqsj <= to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

在今天或者今天之後作比較:

select * from jn_bus_kjlwsbjbxx where dqsj > to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

select * from jn_bus_kjlwsbjbxx where dqsj >= to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

select * from jn_bus_kjlwsbjbxx where dqsj = to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

在某段時間內的比較:

select * from jn_bus_kjlwsbjbxx where dqsj between to_date('2007-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

select * from jn_bus_kjlwsbjbxx where dqsj < to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and update > to_date('2007-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

select * from jn_bus_kjlwsbjbxx where dqsj <= to_date('2007-09-07 00:00:00','yyyy-mm-dd hh24:mi:ss') and update >= to_date('2007-07-07 00:00:00','yyyy-mm-dd hh24:mi:ss')

select * from zyzb_jz_fdmhl_zph where dqsj > to_date('2014-09-20','yyyy-mm-dd') --時間比較--預設時分秒為 00:00:00

select * from zyzb_jz_fdmhl_zph where dqsj > to_date('2014-09-20','yyyy-mm-dd hh24:mi:ss') --時間比較

select * from zyzb_jz_fdmhl_zph where dqsj > to_date('2014-09-20 23:59:59','yyyy-mm-dd hh24:mi:ss') --時間比較--精確時分秒

select * from zyzb_jz_fdmhl_zph where dqsj = to_date('2014-09-23 03:25:00','yyyy-mm-dd hh24:mi:ss')--時間比較--精確時分秒

select * from zyzb_jz_fdmhl_zph where to_char(dqsj,'yyyy-mm-dd') = '2014-09-23'--時間比較--精確時分秒--to_char

同一時刻的日期條件(同一天,某具體時刻)

select ids , dcno , dc , allcount , gkgl , gkgl_zb , gkdl , gkdl_zb , dkgl , dkgl_zb , dkdl , dkdl_zb , hm , hm_zb , mn , mn_zb , lzym , lzym_zb , haomrq , dqsj

from stati_rlgl_pmcsrb_zh where 1=1 and '2017-10-24' = to_char(haomrq,'yyyy-mm-dd') order by dcno asc

select ids , dcno , dc , allcount , gkgl , gkgl_zb , gkdl , gkdl_zb , dkgl , dkgl_zb , dkdl , dkdl_zb , hm , hm_zb , mn , mn_zb , lzym , lzym_zb , haomrq , dqsj

from stati_rlgl_pmcsrb_zh where 1=1 and haomrq = to_date('2017-10-24 09:12:23','yyyy-mm-dd hh24:mi:ss') order by dcno asc

向date型別插入自動的系統時間 ,haomrq, dqsj都是date型別的資料

insert into stati_rlgl_pmcsrb_zh(ids , dcno , dc , allcount , gkgl , gkgl_zb , gkdl , gkdl_zb , dkgl , dkgl_zb , dkdl , dkdl_zb , hm , hm_zb , mn , mn_zb , lzym , lzym_zb , haomrq, dqsj)

values(666,2,'三期',100,7,7,7,7,7,10,7,7,7,7,15,7,7,7,sysdate,sysdate);

oracle語句查詢昨天的資料

select ids , dcno , dc , allcount , gkgl , gkgl_zb , gkdl , gkdl_zb , dkgl , dkgl_zb , dkdl , dkdl_zb , hm , hm_zb , mn , mn_zb , lzym , lzym_zb , haomrq , dqsj

from stati_rlgl_pmcsrb_zh where dc = '一期' and to_char(haomrq,'yyyy-mm-dd')=to_char(sysdate-1,'yyyy-mm-dd') order by dcno asc

注:其中dqsj是y-m-d h:i:s 日期時間格式的

$time=date("y-m-d h:i:s",time());

$sql="select * from 表名 where s_time < to_date('".$time."','yyyy-mm-dd hh24:mi:ss') and e_time > to_date('".$time."','yyyy-mm-dd hh24:mi:ss')";

**:

ACCESS資料庫比較日期和時間

系統使用access資料庫時,查詢時怎麼比較日期和時間呢?為什麼常常比較出來卻是錯誤的呢?比如早的日期比遲的日期大?在asp中先做乙個小測試,就是比較兩個日期,如下 2007 10 01 結果顯示為 true 奇怪了,為什麼大日期還小呢?把日期的雙引號去掉,還是返回 true 那是怎麼回事呢?原來是...

oracle資料庫時間戳轉為日期

select to char timestamp 1000 60 60 24 to date 1970 01 01 08 00 00 yyyy mm dd hh24 mi ss yyyy mm dd as createtime from table這裡的原理是用to date函式將字串 1970 0...

oracle日期時間比較

select cicai as merchantname,tre.bank code as bankcode,sum tr.trade sum as totalmount,count as count,tr.biz type as biztype from trade relation tre,tr...