Oracle exception Propagation

Source: Internet
Author: User


Propagation of oracle exception SQL code www.2cto.com procedure test1 (p_RETCODE in out varchar2, p_retInfo in out varchar2); procedure test2 (p_RETCODE in out varchar2, p_retInfo in out varchar2 ); procedure test3 (p_RETCODE in out varchar2, p_retInfo in out varchar2); SQL code procedure test1 (p_RETCODE in out varchar2, p_retInfo in out varchar2) is begin insert into tree_tb (id, NODE_NAME) values ('1', '1'); test2 (p_R ETCODE, p_retInfo); if p_RETCODE <> 1 then raise test_exception; end if; if 1 = 1 then p_RETCODE: = '-1'; p_retInfo: = 'test1 insertion exception. '; Raise test_exception; end if; p_RETCODE: = '1'; p_retInfo: = 'test1 inserted successfully. '; Exception WHEN test_exception then DBMS_OUTPUT.PUT_LINE ('error Code' | p_RETCODE |': '| p_retInfo); rollback; when others then p_RETCODE: = SQLCODE; p_retInfo: = SUBSTR (SQLERRM, 1, 1000); DBMS_OUTPUT.PUT_LINE ('error Code' | p_RETCODE | ':' | p_retInfo); rollback; end; -- procedure test2 (p_RETCODE in out varchar2, p_retInfo in out varchar2) is begin insert into tree_tb (id, NODE_NAME) Values ('2', '2'); insert into tree_tb (id, NODE_NAME) values ('3', '3'); if 1 = 1 then p_RETCODE: = '-2'; p_retInfo: = 'insertion 2 failed'; raise test_exception; end if; insert into tree_tb (id, NODE_NAME) values ('4', '4 '); p_RETCODE: = '1'; p_retInfo: = 'test2 is successfully inserted. '; Exception WHEN test_exception then dbms_output.put_line ('errorcode:' | p_RETCODE | 'errorinfo' | p_fo retin); rollback; when others then p_RETCODE: = SQLCODE; p_retInfo: = SUBSTR (SQLERRM, 1, 1000); DBMS_OUTPUT.PUT_LINE ('error Code' | p_RETCODE | ':' | p_retInfo); rollback; end;/*** @ Author: ma hongmin * @ function description: test the atomicity and consistency of transactions when a stored procedure calls multiple stored procedures at the same time * @ param retcode out returns the encoding * @ param retinfo out returns the information corresponding to the encoding */procedure test3 (p_RETCODE in out varchar2, p_retInfo in out varchar2) is begin test1 (p_RETCODE, p_retInfo); if p_RETCODE <> 1 then raise test_exception; end if; insert into tree_tb (id, NODE_NAME) values ('5 ', '5'); exception WHEN test_exception then response ('errorcode: '| p_RETCODE | 'errorinfo' | p_retInfo); rollback; when others then p_RETCODE: = SQLCODE; p_retInfo: = SUBSTR (SQLERRM, 1, 1000); DBMS_OUTPUT.PUT_LINE ('error Code' | p_RETCODE | ':' | p_retInfo); rollback; end;

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

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.