Oracle Stored Functions

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
  1. create or replace function queryempincoming(eno in number)
  2. return number
  3. as
  4. --定义一个变量保存员工的的薪水和奖金
  5. psal emp.sal%type;
  6. pcomm emp.comm%type;
  7. begin
  8. select sal,comm into psal,pcomm from emp where empno=eno;
  9. --直接返回年收入
  10. return psal*12+nvl(pcomm,0);
  11. 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

 

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326123017&siteId=291194637