Oracle 函数小例子

来源:互联网 发布:安卓数据访问 编辑:程序博客网 时间:2024/04/30 08:15

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);

原创粉丝点击