Oracle 計算時間格式平均值的sql 語句
select to_char((to_date('2019-07-01', 'yyyy-mm-dd') + numtodsinterval(avg(begin_time_second), 'second')),'hh24:mi:ss') avg_begin_time,to_char((to_date('2019-07-01', 'yyyy-mm-dd') + numtodsinterval(avg(end_time_second), 'second')),'hh24:mi:ss') avg_end_time--2019-07-01 00:00:00 + numtodsinterval(平均數,'秒')轉換為日期格式,然后再轉換為 時間字符格式from ( select --把上班時間換算為秒 to_char(a.actontime, 'hh24') * 3600 + to_char(a.actontime, 'mi') * 60 + to_char(a.actontime, 'ss') as begin_time_second, --把下班時間換算為秒 to_char(a.actofftime, 'hh24') * 3600 + to_char(a.actofftime, 'mi') * 60 + to_char(a.actofftime, 'ss') as end_time_second from empworkdate a)
知識點擴展:oracle中獲取年月日時分秒
我寫sql的時間為2016年10月10日下午15:18完事,這個時間下面要做對比:
--獲取年select to_char(sysdate,'yyyy') from dual--2016select to_char(sysdate,'YYYY') from dual--2016--獲取月select to_char(sysdate,'mm') from dual--10select to_char(sysdate,'MM') from dual--10--獲取日select to_char(sysdate,'dd') from dual--10select to_char(sysdate,'DD') from dual--10--獲取時select to_char(sysdate,'hh24') from dual--15select to_char(sysdate,'hh') from dual--03select to_char(sysdate,'HH') from dual--03select to_char(sysdate,'HH24') from dual--15--獲取分鐘select to_char(sysdate,'MI') from dual--14select to_char(sysdate,'mi') from dual--14--獲取秒select to_char(sysdate,'ss') from dual--35select to_char(sysdate,'SS') from dual--40--獲取年月日時分秒select to_char(sysdate,'yyyy-mm-dd hh:mi:ss') from dual--2016-10-10 03:17:25select to_char(sysdate,'yyyy-mm-dd hh24:mi:ss') from dual--2016-10-10 15:17:51
(1)從上面的測試SQL可以看出年月日yyyy,mm,dd,hh,mi,ss的大小寫對于從oracle中獲取年月日時分秒沒有影響
(2)對于獲取小時分12小時和24小時的情況,如果你想獲取顯示下午的時間,你可以采用hh24,這樣就會顯示類似于15:30而不是03:30
總結
以上所述是小編給大家介紹的Oracle 計算時間格式平均值的sql 語句,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復大家的。在此也非常感謝大家對武林網網站的支持!
如果你覺得本文對你有幫助,歡迎轉載,煩請注明出處,謝謝!
新聞熱點
疑難解答