首页 > 数据库 > Oracle > 正文

在Oracle中实现时间相加处理

2024-08-29 13:36:01
字体:
来源:转载
供稿:网友

  -- 名称: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

发表评论 共有条评论
用户名: 密码:
验证码: 匿名发表