views:

59

answers:

2

I was trying to come up with a real life programming problem that could be best solved by using autonomous transactions within autonomous transactions but could not think of any.

Can you give me any ideas?

Edit:

I mean something like this:

PROCEDURE outer_procedure
IS
BEGIN
  -- some code
  auto_proc1;
END;
/

PROCEDURE auto_proc1
IS PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  -- some code
  auto_proc2;
END;
/

PROCEDURE auto_proc2
IS PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
  -- some code
  NULL;
END;
/
A: 

It's could be bit of a stretch, but I believe that this is a relatively common case in integration scenarios:

I had a situation where I needed to invoke a third party program that relied upon data committed to the database, but my business logic running in the outer transaction relied on the return from this third party program. This required that I use a nested (autonomous) transaction for the data needed by the third party program, and a separate transaction for the data incorporating the return of the third party program.

Zoran Regvart
+1  A: 

Autonomous transactions can be usefull for situations like:

  • When you want to log information about a transaction in a table, even if that transaction fails/is rolled back. If you would do that without autonomous transactions, the logging will be rolled back also.

  • If you have a long transaction that needs a short lock on a table that is also used by other threads. If you do this in an autonomous transaction, the lock will be held shortly, even if the transaction takes a long time.

Edwin
These two do not require using more than a single level of autonomous transactions.
jva
Sorry, without the clarification I did not understand what you meant.I never used it in real life, but you can have this in the following example: A combination of these 2:You need an autonomous transaction (for example because you do not want to keep a lock open), but always want to log the result of this transaction in a table regardless of the result (commit/rollback) of the main autonomous transaction.
Edwin