zoukankan      html  css  js  c++  java
  • ORACLE NOCOPY的用法

    DECLARE
      l_1 NUMBER := 10;
      l_2 NUMBER := 20;
      l_3 NUMBER := 30;
      PROCEDURE test_out(p1 IN NUMBER,
                         x1 IN OUT NUMBER,
                         x2 IN OUT NOCOPY NUMBER) IS
      BEGIN
        x1 := p1;
        dbms_output.put_line('inside test_out, x1=' || x1);
        x2 := p1;
        dbms_output.put_line('inside test_out, x2=' || x2);
         (--)raise_application_error(-20005, 'test NOCOPY');
      END;
    BEGIN
      dbms_output.put_line('before, l_1=' || l_1 || ', l_2=' || l_2 ||
                           ', l_3=' || l_3);
      BEGIN
        --the OUT parameter has no value at all until the program terminates successfully,  
        --unless you have requested use of the NOCOPY hint  
        test_out(l_1, l_2, l_3);
      EXCEPTION
        WHEN OTHERS THEN
          dbms_output.put_line('SQLCODE => ' || SQLCODE || ', SQLERRM => ' ||
                               SQLERRM);
      END;
      dbms_output.put_line('after, l_1=' || l_1 || ', l_2=' || l_2 || ', l_3=' || l_3);
    END;

    如果不mark掉 raise_application_error,輸出結果:

    before, l_1=10, l_2=20, l_3=30
    inside test_out, x1=10
    inside test_out, x2=10
    SQLCODE => -20005, SQLERRM => ORA-20005: test NOCOPY
    after, l_1=10, l_2=20, l_3=10

    如果mark掉 raise_application_error,輸出結果:

    before, l_1=10, l_2=20, l_3=30
    inside test_out, x1=10
    inside test_out, x2=10
    after, l_1=10, l_2=10, l_3=10

    得出結論:

           out 參數在程序正常下,是要返回賦予其值,而出現錯誤時,則不作任何處理,即使在賦值之後,仍然還是原值。

           out nocopy 則是在程序出現錯誤情況下,仍然返回賦值之後的值。

          

  • 相关阅读:
    矩阵问题
    链表问题
    PHP8确认支持JIT,加上Swoole后快到飞起
    五面阿里,顺利拿下PHP研发岗offer,这些技术点你未必掌握了
    php-laravel框架用户验证(Auth)模块解析(一)
    php laravel请求处理管道(装饰者模式)
    Redis常见七种使用场景(PHP实战)
    PHP fastcgi_finish_request 方法
    Linux 下编写一个 PHP 扩展
    创 PHP RSA2 签名算法
  • 原文地址:https://www.cnblogs.com/Mayvar/p/wanghonghua_201109210208.html
Copyright © 2011-2022 走看看