I’m doubting a bit. Let’s assume this package’s procedures:
PROCEDURE ERR_MANAGER(I_ERRM IN VARCHAR2) IS
BEGIN
ROLLBACK;
--DO SOME STUFF
END ERR_MANAGER;
PROCEDURE test IS
PRAGMA AUTONOMOUS_TRANSACTION;
BEGIN
test2;
COMMIT;
EXCEPTION WHEN OTHERS THEN ERR_MANAGER(SQLERRM);
END test;
PROCEDURE test2 IS
BEGIN
--DO SOME TRANSACTIONNAL DML
RAISE_APPLICATION_ERROR(-20001, 'ERR'); --for the test purpose, in reality this could be any actual error
END test2;
So, as you can see there’s an error in test2(), which is going to raise up to test(), and then be handled in the err_manager() method.
So I have 2 questions:
- what’s the scope of err_manager()? Is it still within the autonomous transaction? I guess so, since it is only a function call, but I’d like to be sure
- what’s happening if you exit an autonomous transaction brutally because of an error raising to upper levels, without proceeding any kind of commit or rollback?
Thank you very much.
S.
The transaction scope of the execution of the
err_managerprocedure is the calling autonomous transaction, you are correct.Procedures and functions inherit their calling transactions unless they are themselves autonomous transactions.
When an autonomous transaction raises an unhandled error, it rollbacks its changes and the error propagates to the calling application. Here’s a test: