oracle PL/SQL编程语言之out关键字的使用

(本文章内容仅在windows10下经测试能够运行,不能保证其他环境下的可靠性)

 

通过使用out关键字,使得存储过程能够返回数据

 

案例场景:使用存储过程实现计算emp表指定员工编号的员工的年薪

创建存储过程示例代码如下:

create or replace procedure p_yearsal(eno emp.empno%type,yearsal out number)
as
sal number(10);
comm number(10);
begin
  select sal,nvl(comm, 0) into sal,comm from emp where empno = eno;
  yearsal := sal * 12 + comm;
end;

 

测试使用存储过程代码如下:

declare
  s number(10);
begin
  p_yearsal(7788,s);
  dbms_output.put_line(s);
end;

注意:使用out关键字的参数必须在存储过程业务逻辑中使用into或:=赋值,否则报错。

posted @ 2020-06-06 23:00  DNoSay  阅读(310)  评论(0编辑  收藏  举报