7. plsql function

The function
function is used to return specific data. When creating a function, the return clause must be included in the function header, and the data returned by the return statement must be included in the function body. We can use create function to create a function. The actual case:

-- Function case
  -- enter the employee's name and return the employee's annual salary
  create function annual_income(sunName varchar2) return
  number is annual_salary number(7,2);
  begin --execute
    part
    select sal*12+nvl(comm,0)*12 into annual_salary from emp where ename=sunName;
    return annual_salary;
    end;


call the function in sqlplus
sql>var income number//Define a variable
SQL>call annual_income('SCOTT') into:income;//The value returned by the function
SQL >print income;


Similarly, we can call the function
select annual_income('SCOTT') from dual in the java program;
//This way, we can get the returned result through rs.getInt(1).

Guess you like

Origin http://10.200.1.11:23101/article/api/json?id=326998376&siteId=291194637