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-
·
在今天或者今天之前作比较:
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
开放原子开发者工作坊旨在鼓励更多人参与开源活动,与志同道合的开发者们相互交流开发经验、分享开发心得、获取前沿技术趋势。工作坊有多种形式的开发者活动,如meetup、训练营等,主打技术交流,干货满满,真诚地邀请各位开发者共同参与!
更多推荐
已为社区贡献1条内容
所有评论(0)