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 則是在程序出現錯誤情況下,仍然返回賦值之後的值。

          

  • 相关阅读:
    锋利的jQuery复制粘贴(一)
    使用photoshop以及markman进行快速重构页面的几个步骤
    线程间同步之 semaphore(信号量)
    关于C#中Thread.Join()的一点理解
    无废话WCF入门教程一[什么是WCF]
    Oracle function注释
    throw new DataException("检查服务器是否存在失败:" + ex);
    C# 将数据集以excel的形式输出
    .net 安装remoting服务
    任务计划 每日删除设定目录内的文件(包括文件夹)
  • 原文地址:https://www.cnblogs.com/Mayvar/p/wanghonghua_201109210208.html
Copyright © 2011-2022 走看看