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; -- 得出時間相加后的結(jié)果 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