a definition
Function is an unnamed stored procedure that can take parameters and return a computed value.
Functions and procedures are similar in structure, but must have a return clause that returns the function value.
two grammar
ccreate[or replace] FUNCTION function name (parameter list)
return function value type
AS
PLSQL subroutine body;
Three needs
Query the annual income of an employee
four code
create or replace function queryempincoming(eno in number)
return number
as
--定义一个变量保存员工的的薪水和奖金
psal emp.sal%type;
pcomm emp.comm%type;
begin
select sal,comm into psal,pcomm from emp where empno=eno;
--直接返回年收入
return psal*12+nvl(pcomm,0);
end;
Five call stored procedures
Select the function, right-click and select "Run". Enter an employee number. Run, output the employee number.
v_Return = 43500