ORACLE NOCOPY的用法

來源:互聯網
上載者:User

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

      

 

 

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.