函数:将秒数转化为相对时间

函数名:get_time_zdp

参数:seconds 秒数

功能:将秒数转化为相对时间

举例:select get_time_zdp(2*60*60*24*30+2*60+3*60*60) from dual;         

         --2个月3小时2分0秒

 

代码:

create or replace function get_time_zdp(
  seconds in number
) 
return varchar2 as
  temp   number;
  years  number;
  months number;
  days number;
  hour   number;
  minit  number;
  sec    number;
  RET    VARCHAR2(100);
begin
  temp :=seconds;    
  if ( round(temp/(60*60*24*30*12))>0) then  
      years  :=floor(temp/(60*60*24*30*12));    --一年按12个月记 
             temp :=temp -years*(60*60*24*30*12);
             dbms_output.put_line(temp);
      RET :=RET||years||'年';
  end if;
  if( floor(temp/(60*60*24*30))>0) then
      months :=floor(temp/(60*60*24*30));       --一个月按30天记
             temp :=temp -months*(60*60*24*30);
             dbms_output.put_line(temp);
      RET :=RET||months||'个月';
  end if;
  if( floor(temp/(60*60*24))>0) then
      days :=floor(temp/(60*60*24));
           temp :=temp -days*(60*60*24);
           dbms_output.put_line(temp);
      RET :=RET||days||'天'; 
  end if; 
  if( floor(temp/(60*60))>0) then
      hour :=floor(temp/(60*60));
           temp :=temp -hour*(60*60);
           dbms_output.put_line(temp);
      RET :=RET||hour ||'小时';
  end if;
  if( floor(temp/60)>0) then
      minit :=floor(temp/60);
           temp :=temp -minit*60;
           dbms_output.put_line(temp);
      RET :=RET||minit ||'分';
  end if;
  
  RET :=RET||temp || '秒';
  return RET;
end;

 

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值