oracle(41)_PL/SQL_存储函数
PL/SQL
存储函数
● 存储函数
- 语法:
create or replace function 函数名(Name in type, Name in type, .. .) return 数据类型 is 结果变量 数据类型; begin return(结果变量); end 函数名;
● 存储过程和存储函数的区别
-
一般来讲,过程和函数的区别在于函数可以有一个返回值;而过程没有返回值。 但过程和函数都可以通过 out 指定一个或多个输出参数。我们可以利用 out 参数,在过程和函数中实现返回多个值。
-
范例:使用存储函数来查询指定员工的年薪
-
示例图:
● 以上操作完整源码:
create or replace function countysalf(pno in emp.empno%type) return number is
FunctionResult number;
psal emp.sal%type;
pcomm emp.comm%type;
begin
select t.sal,t.comm into psal,pcomm from emp t where t.empno = pno;
FunctionResult := psal * 12 + nvl(pcomm, 0);
return(FunctionResult);
end countysalf;
begin
-- Call the function
:result := countysalf(pno => :pno);
end;
如有错误,欢饮指正!