CREATE OR REPLACE FUNCTION to_percent
(a in number,b in number)
return varchar2
is
c varchar2(20);
begin
if(a=0 or b=0)
then
c:='0.00%';
else
c:=to_char( trunc(a*100/b,2),'fm9999999990.00')||'%';
end if ;
if(c='%')
then
c:='0.00%';
end if;
return c;
end;
调用函数:
在SQL下
SQL>var(variable) per number;
SQL>execute :per:=to_percent(20,50);