Home > Database > Mysql Tutorial > Oracle函数 通过秒数或分钟数获取时间段

Oracle函数 通过秒数或分钟数获取时间段

WBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWBOYWB
Release: 2016-06-07 17:11:11
Original
1133 people have browsed it

一同事叫帮忙写个函数,通过输入分钟数或秒数,获取一个时间段,尽管很简单,也还是贴出来一备需要的时候,直接拿来用: create

一同事叫帮忙写个函数,通过输入分钟数或秒数,获取一个时间段,,尽管很简单,也还是贴出来一备需要的时候,直接拿来用:

create or replace function get_time(i_time in number, flag in varchar2) return varchar2 is

    Result varchar2(100);

/*

  i_time : 输入的时间数字

  flag   :分钟还是秒的判断 0:分钟;1:秒

*/

    total_ss           number;

    total_mi           number;

    total_Second      number;

    total_hh           number;

    total_minus       number;

begin

  if flag = '0' then

        total_ss := i_time*60;

  else

      total_ss := i_time; 

  end if; 

  total_mi       := trunc(total_ss/60);

  total_Second   := mod(total_ss,60);

  if total_mi >=60 then

       total_hh    := trunc(total_mi/60); 

     total_minus := mod(total_mi,60);

  else

     total_hh    := 0;

     total_minus := total_mi;  

  end if;

 

  if total_mi = 0 then

       Result := to_char(total_Second)||'秒';

  elsif total_hh = 0 then

     Result := to_char(total_minus)||'分'||to_char(total_Second)||'秒';  

  elsif total_hh >0 then

     Result := to_char(total_hh)||'时'||to_char(total_minus)||'分'||to_char(total_Second)||'秒';        

  else

     Result := 'error'; 

  end if;

 

  return(Result);

end get_time;

linux

Related labels:
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template