Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Rollback + Commit some changes

I have a case where I need to Rollback changes on the Database, but also, I want to keep the inserted Logs.

Illustration:

Add processing log
 Insert some data
 Insert some data
 Insert some data
Add processing log
 Do some checking...
  Checking Failed
  Add processing log
  Rollback;
  • Log table on the same database of the other inserted data

Is there any way to achieve this ?

like image 519
sameh.q Avatar asked Jan 28 '26 20:01

sameh.q


1 Answers

There is, I would normally expect a centralized logging routine and in that logging package, in the function you use to write the log, insert this line after the procedure header declaration

  PRAGMA AUTONOMOUS_TRANSACTION;

That will place the log insertions on a different transaction to the calling routine, allowing you to commit the log regardless of what happens in the parent routine.

Docs Details : http://docs.oracle.com/cd/B28359_01/appdev.111/b28370/autotransaction_pragma.htm

like image 112
Andrew Avatar answered Jan 31 '26 11:01

Andrew



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!