秒转为时分秒的oracle函数
2016-06-12 16:14
453 查看
create or replace function GETTIMEDESC(seconds in integer) return varchar2 is Result varchar2(100); begin Result := '1t'; if (seconds<24*3600) then select to_char(to_date(mod(seconds,3600*24),'sssss'),'fmhh24"小时"mi"分"ss"秒"') into Result from dual; else select trunc(seconds/3600/24) || '天' || to_char(to_date(mod(seconds,3600*24),'sssss'),'fmhh24"小时"mi"分"ss"秒"') into Result from dual; end if; return(Result); end GETTIMEDESC;
这个函数没有太多的技术含量,记录下来。网上找了好久,后来也是看一个答案,稍加改造而来
调用sql语句 select GETTIMEDESC(500000) m from dual;
好像又回去了,写来写去,感觉很简单,但是网上就没有这个现成的答案,简单是事情我来做。
调试了好久,发现上面的写法是有问题的,换个写法,搞了好久,实在是不成了,只好整个笨办法,麻烦点,但肯定是对的。
create or replace function GETTIMEDESC(seconds in number) return varchar2 is Result varchar2(100); --DaySeconds number; TempSconds number; begin Result := ''; --DaySeconds := 24*3600; TempSconds := seconds; if (seconds is null) then return ''; end if; --天数 if (seconds>=86400) then Result := round(seconds/86400) || '天'; TempSconds := mod(seconds,86400); else Result := '0天'; end if; --小时 if (TempSconds>=3600) then Result := Result || round(TempSconds/3600) || '小时'; TempSconds := mod(TempSconds,3600); else Result := Result || '0小时'; end if; --分钟 if (TempSconds>=60) then Result := Result || round(TempSconds/60) || '分钟'; TempSconds := mod(TempSconds,60); else Result := Result || '0分钟'; end if; Result := Result || to_char(round(TempSconds)) || '秒'; return(Result); end GETTIMEDESC;
对自己来说是个记录,希望对需要的人能或多或少地帮助一点点
相关文章推荐
- Oracle Forall
- weka-Oracle数据库连接及以ARFF文件导出[2]
- 对oracle实例的内存(SGA和PGA)进行调整,优化数据库性
- ORACLE 专用服务器模式(DEDICATED)与共享服务器模式(SHARE)的区别
- Oracle存储过程基本语法 存储过程
- 为你介绍Oracle 11g数据库每天自动备份的实现方法
- ORA-100501: non-ORACLE exception
- Oracle EBS R12 电子技术参考手册 - eTRM (电子文档)
- trunc(sysdate)的含义是什么
- Oracle11.2新特性之listagg函数(多条数据用逗号隔开)
- ORACLE 表如何count最快?
- Oracle 导入dmp文件命令
- Entity Framework 6 Database-first连接Oracle11g
- python连接oracle数据库
- PL/SQL查询oracle数据库对象
- oracle利用flashback 闪回功能恢复delete数据
- Oracle 的安装与配置
- oracle 如何搜索当前用户下所有表里含某个值的字段?(转)
- oracle第四章复习
- ORA-00020: maximum number of processes (xxxx) exceeded 报错解决方法