Oracle 計算時間格式平均值的sql 語句
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(平均數(shù),'秒')轉(zhuǎn)換為日期格式,然后再轉(zhuǎn)換為 時間字符格式
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--2016 select to_char(sysdate,'YYYY') from dual--2016 --獲取月 select to_char(sysdate,'mm') from dual--10 select to_char(sysdate,'MM') from dual--10 --獲取日 select to_char(sysdate,'dd') from dual--10 select to_char(sysdate,'DD') from dual--10 --獲取時 select to_char(sysdate,'hh24') from dual--15 select to_char(sysdate,'hh') from dual--03 select to_char(sysdate,'HH') from dual--03 select to_char(sysdate,'HH24') from dual--15 --獲取分鐘 select to_char(sysdate,'MI') from dual--14 select to_char(sysdate,'mi') from dual--14 --獲取秒 select to_char(sysdate,'ss') from dual--35 select to_char(sysdate,'SS') from dual--40 --獲取年月日時分秒 select to_char(sysdate,'yyyy-mm-dd hh:mi:ss') from dual--2016-10-10 03:17:25 select 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
總結(jié)
以上所述是小編給大家介紹的Oracle 計算時間格式平均值的sql 語句,希望對大家有所幫助,如果大家有任何疑問請給我留言,小編會及時回復(fù)大家的。在此也非常感謝大家對腳本之家網(wǎng)站的支持!
如果你覺得本文對你有幫助,歡迎轉(zhuǎn)載,煩請注明出處,謝謝!
相關(guān)文章
Oracle連接數(shù)據(jù)庫提示ORA-12638:身份證明檢索失敗的解決辦法
今天在使用應(yīng)用程序連接Oracle時碰到了"ORA-12638:身份證明檢索失敗"錯誤,給大家總結(jié)解決方法,這篇文章主要給大家介紹了關(guān)于Oracle連接數(shù)據(jù)庫提示ORA-12638:身份證明檢索失敗的解決辦法,需要的朋友可以參考下2023-10-10
Oracle帶輸入輸出參數(shù)存儲過程(包括sql分頁功能)
這篇文章主要介紹了Oracle帶輸入輸出參數(shù)存儲過程(包括sql分頁功能)的相關(guān)知識,非常不錯,具有一定的參考借鑒價值,需要的朋友可以參考下2018-10-10
Oracle 管道 解決Exp/Imp大量數(shù)據(jù)處理問題
Oracle的exp/imp是許多用戶經(jīng)常使用的兩個工具. 它們常被用來做數(shù)據(jù)庫的邏輯備份,數(shù)據(jù)庫重組和數(shù)據(jù)轉(zhuǎn)移等工作.2009-07-07
oracle數(shù)據(jù)庫查看鎖表的sql語句整理
Oracle數(shù)據(jù)庫操作中,我們有時會用到鎖表查詢以及解鎖和kill進程等操作,這篇文章主要給大家介紹了關(guān)于oracle數(shù)據(jù)庫查看鎖表的sql語句的相關(guān)資料,文中通過代碼介紹的非常詳細,需要的朋友可以參考下2023-10-10

