建立存储函数的语法:
CREATE [OR REPLACE] FUNCTION函数名(参数列表)
RETURN 函数值类型
AS
PLSQL子程序体;
示例:查询某职工的年收入。
SQL> /**/
/*
查询某职工的总收入
*/
create or replace function queryEmpSalary(empid in number)
return number
as
pSal number; --定义变量保存员工的工资
pComm number; --定义变量保存员工的奖金
begin
select sal,comm into psal,pcomm from emp where empno = empid;
return psal*12+nvl(pcomm,0);
end;
/
Function created
l 函数的调用
SQL> declare
v_sal number;
begin
v_sal:=queryEmpSalary(7934);
dbms_output.put_line('salary is:'|| v_sal);
end;
/
salary is:15600
PL/SQL procedure successfully completed
SQL> begin
dbms_output.put_line('salary is:'|| queryEmpSalary(7934));
end;
/
salary is:15600
PL/SQL procedure successfully completed
