一同事叫帮忙写个函数,通过输入分钟数或秒数,获取一个时间段,尽管很简单,也还是贴出来一备需要的时候,直接拿来用:
create or replace function get_time(i_time in number, flag in varchar2) return varchar2 is
Result varchar2(100);
/*
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;
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;