你好,游客 登录 注册 搜索
背景:
阅读新闻

轻轻松松学会在Oracle中实现时间相加处理

[日期:2007-08-20] 来源:Linux公社  作者:Linuxidc [字体:大 中 小]

如何在Oracle中实现时间相加处理?

今天由于项目的需要,我负责编写Oracle中的存储过程。以前从来没有接触过,这次是个很好的学习机会,好好把握!

但是,在使用过程中,遇到一个问题,不知道该如何实现时间相加功能,因为系统中需要用来时间相加功能。通过网络找资料,但是最终一无所获。于是,决定自己写一个!希望可以给朋友有所帮助!

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

linux
相关资讯       oracle 
本文评论   查看全部评论 (0)
表情: 表情 姓名: 字数

       

评论声明
  • 尊重网上道德,遵守中华人民共和国的各项有关法律法规
  • 承担一切因您的行为而直接或间接导致的民事或刑事法律责任
  • 本站管理人员有权保留或删除其管辖留言中的任意内容
  • 本站有权在网站内转载或引用您的评论
  • 参与本评论即表明您已经阅读并接受上述条款