选择显示字体大小

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

  


 


关键字 本文所属关键字

相关 与本文相关文章

分类 所有文章关键字导航

源码编程相关

Java   Asp   PHP   .Net   XML   C/C++   CGI   VB   Jsp   J2ee   J2se   J2me   EJB   Servlet   Tomcat   Resin   Struts   Weblogic   Eclipse   ANT   GUI   JMS   Web servise   IDEA   Webphere   Hibernate   Spring   Jboss   Applet   Swing   Socket   Javamail   Perl   Ajax   P2P   安全   模式   框架   测试   开源   游戏

SQL数据库相关

My-SQL   Ms-SQL   Access   DB2   Oracle   Sybase   SQLserver   索引   存储过程   加密   数据库   分页   视图  

手机无线相关

3G   Wap   CDMA   GRPS   GSM   IVR   彩信   短信   无线   增值业务

网页设计制作相关

HTML   CSS   网页配色   网页特效   Javascript   VBscript   Dreamweaver   Frontpage   JS   Web   网站设计

网站建设推广相关

建站经验   网站优化   网站排名   推广   Alexa

操作系统/服务器相关

Windows XP   Windows 2000   Windows 2003   Windows Me   Windows 9.x   Linux   UNIX   注册表   操作系统   服务器   应用服务器

图形图像多媒体相关

Photoshop   Fireworks   Flash   Coreldraw   Illustrator   Freehand   Photoimpact   多媒体   图形图像

标准 网站致力的规范

Valid CSS!

无不良内容,无不良广告,无恶意代码

Valid XHTML 1.0 Transitional

creativecommons