如何在Oracle中實現時間相加處理? 今天由于項目的需要,老大讓我負責編寫Oracle中的存儲過程。嘿,以前從來沒有接觸過,這次是個很好的學習機會,好好把握! 但是,在使用過程中,碰到一個問題,不知道該如何實現時間相加功能,因為系統中需要用來時間相加功能。通過網絡找資料,但是最終一無所獲。于是,決定自己寫一個!希望可以給朋友有所幫助! -- 名稱:Add_Times -- 功能:返回d1與NewTime相加以后的結果,實現時間的相加 -- 說明:對于NewTime中的日期不予考慮 -- 日期:2004-12-07 -- 版本:1.0 -- 作者:Kevin create or replace function Add_Times(d1 in date,NewTime in date) return date is hh number; mm number; ss number; hours number; dResult date; begin -- 下面依次取出時、分、秒 select to_number(to_char(NewTime,'HH24')) into hh from dual; select to_number(to_char(NewTime,'MI')) into mm from dual; select to_number(to_char(NewTime,'SS')) into ss from dual; -- 換算出NewTime中小時總和,在一天的百分幾 hours := (hh + (mm / 60) + (ss / 3600))/ 24; -- 得出時間相加后的結果 select d1 + hours into dResult from dual; return(dResult); end Add_Times; -- 測試用例 -- select Add_Times(sysdate,to_date('2004-12-06 03:23:00','YYYY-MM-DD HH24:MI:SS')) from dual