Oracle stored procedure with parameters

a need

For the designated employees, increase the salary of 100 yuan; and print the salary before and after the increase.
 
two code
  1. --带参数存储过程:给指定的员工涨100,并且打印涨前和涨后的薪水
  2. /*
  3. 如何调用:
  4. begin
  5. raisesalay(7839);
  6. raisesalay(7566);
  7. commit;
  8. end;
  9. /
  10. */
  11. create or replace procedure raisesalay(eno in number)
  12. as
  13. --定义一个变量保存涨前的薪水
  14. psal emp.sal%type;
  15. begin
  16. select sal into psal from emp where empno=eno;
  17. update emp set sal=sal+100where empno=eno;
  18. --需不需要commit
  19. --注意:一般不在存储过程或存储函数中提交和回滚,由调用者来进行提交或回滚
  20. dbms_output.put_line('涨前:'||psal||'涨后:'||(psal+100));
  21. end;
  22. /
 
Three calls to the stored procedure
SQL> begin
  2   raisesalay(7839);
  3   raisesalay(7566);
  4   commit;
  5  end;
  6  /
Before rising: 10000 After rising: 10100
Before the rise: 6975 After the rise: 7075
 
PL/SQL procedure completed successfully.

Guess you like

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