ITPub博客

首页 > Linux操作系统 > Linux操作系统 > unhandled exception with NOCOPY

unhandled exception with NOCOPY

原创 Linux操作系统 作者:dragondb 时间:2019-03-18 20:09:06 0 删除 编辑

两个匿名块唯一的区别是:第一个没有使用NOCOPY hint,第二个使用了:

SQL> set serverout on;
SQL> declare
  2  lv_int   PLS_INTEGER := 1;
  3  procedure p_test(p_int IN OUT PLS_INTEGER)
  4  is
  5    exp exception;
  6  begin
  7   p_int := p_int +2;
  8   raise exp;
  9  exception
 10    when others then
 11     dbms_output.put_line('1:'||p_int);
 12     raise;
 13  end p_test;
 14  begin
 15   p_test(lv_int);
 16  exception
 17    when others then
 18      dbms_output.put_line('2:'||lv_int);
 19  end;
 20  /
1:3
2:1

PL/SQL procedure successfully completed.

SQL>
SQL> declare
  2  lv_int   PLS_INTEGER := 1;
  3  procedure p_test(p_int IN OUT NOCOPY PLS_INTEGER)
  4  is
  5     exp exception;
  6  begin
  7   p_int := p_int +2;
  8   raise exp;
  9  exception
 10    when others then
 11     dbms_output.put_line('1:'||p_int);
 12     raise;
 13  end p_test;
 14  begin
 15   p_test(lv_int);
 16  exception
 17    when others then
 18      dbms_output.put_line('2:'||lv_int);
 19  end;
 20  /
1:3
2:3

PL/SQL procedure successfully completed.

对于unhandled exception,OUT/IN OUT的形参的值不会传递给实参,所以第一个匿名块第二步输出初始值1, 但是如果有NOCOPY hint,OUT/IN OUT的形参的值会传递给实参,也就是在这种情况下是会影响实参的值的,第二个匿名块输出更新后的值3;

 

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/45259/viewspace-659935/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2003-05-05

  • 博文量
    98
  • 访问量
    94093