oracle中日期和数字相加,如何在Oracle中实现时间相加处理?[原创]-数据库专栏,ORACLE...

如何在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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值