当前位置: 移动技术网 > IT编程>数据库>Oracle > oracle实现动态查询前一天早八点到当天早八点的数据功能示例

oracle实现动态查询前一天早八点到当天早八点的数据功能示例

2020年03月09日  | 移动技术网IT编程  | 我要评论

6岁女童被藏獒咬断脖子,章子怡和多少人睡过,陈思思的老公

本文实例讲述了oracle实现动态查询前一天早八点到当天早八点的数据。分享给大家供大家参考,具体如下:

需要查询前一天早八点到当天早八点的数据

这里是查询sql语句

select
  dept_id,
  count( * ) did
from
  "mes_mach_call_event"
where
  call_time >= trunc(sysdate-1)+8/24
  and call_time <= trunc(sysdate)+8/24
group by
  dept_id

现在单独来看一下获取系统当天八点和前一天八点的方法

select trunc(sysdate)+8/24 from dual;
select trunc(sysdate-1)+8/24 from dual;

+8/24为24小时制中的早八点

其中trunc函数的用法为

【trunc(for dates)】trunc()函数处理日期

语法格式:trunc(date[,fmt])

其中:date 一个日期值;fmt 日期格式。

该日期将按指定的日期格式截取;忽略它则由最近的日期截取。

示例:

select trunc(sysdate) from dual;–2017/2/13,返回当前时间 
select trunc(sysdate,'yy') from dual;–2017/1/1,返回当年第一天 
select trunc(sysdate,'mm') from dual;–2017/2/1,返回当月的第一天 
select trunc(sysdate,'d') from dual;–2017/2/12,返回当前星期的第一天,即星期天 
select trunc(sysdate,'dd') from dual;–2017/2/13,返回当前日期,今天是2017/2/13 
select trunc(sysdate ,'hh24') from dual;–2017/2/13 15:00:00,返回本小时的开始时间 
select trunc(sysdate ,'mi') from dual;–2017/2/13 15:13:00,返回本分钟的开始时间

如对本文有疑问,请在下面进行留言讨论,广大热心网友会与你互动!! 点击进行留言回复

相关文章:

验证码:
移动技术网