Oracle 数据库比较日期大小
在今天或者今天之前作比较:
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
写博客是为了记住自己容易忘记的东西,另外也是对自己工作的总结,文章可以转载,无需版权。希望尽自己的努力,做到更好,大家一起努力进步!
如果有什么问题,欢迎大家一起探讨,代码如有问题,欢迎各位大神指正!