时间:2021-07-01 10:21:17 帮助过:34人阅读
一同事叫帮忙写个函数,通过输入分钟数或秒数,获取一个时间段,尽管很简单,也还是贴出来一备需要的时候,直接拿来用: 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;