Skip to Main Content

SQL & PL/SQL

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Rollback when handling exceptions

user12093849May 18 2015 — edited May 18 2015

Hi

I am trying to handle the errors between each DML statements. when the code runs and it fails between the DML statement and half of the tables are committed and gives me the unexpected result.

Please let me know how to avoid this?

Is every DML statement to be written with each error handling block? or any other better way than this using Savepoint?

begin

insert statement 1;

commit;


insert statement 2;

commit;


update statement statement 1

commit;


delete statement 1;

commit;

EXCEPTION

  WHEN DUP_VAL_ON_INDEX THEN

  proc_stat_util.write_msg('E', 'Unique constraint Error: Please check if any record is there at '|| v_tablename || 'table');

  raise_application_error(-20001, 'Unique constraint Error: Please check if any record is there at '|| v_tablename || 'table');

  WHEN OTHERS THEN

  ROLLBACK;

  RAISE_APPLICATION_ERROR(-20001,'ORACLE ERROR: '||DBMS_UTILITY.FORMAT_ERROR_STACK );

End;

Thanks a lot in advance

This post has been answered by Jarkko Turpeinen on May 18 2015
Jump to Answer
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jun 15 2015
Added on May 18 2015
8 comments
1,592 views