在今天或者今天之前作比较:
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 日期时间格式的

其中我参考得到的sql语句:
 $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')";


转自:https://www.cnblogs.com/summary-2017/p/7263220.html

 

Logo

有“AI”的1024 = 2048,欢迎大家加入2048 AI社区

更多推荐