One or several autonomous transactions can be defined in one of your transactions (outer transactions. An autonomous transaction can be committed independently without affecting the outer transaction. Similarly, the rollback of the outer transaction does not affect the autonomous transaction. Generally, you can consider defining an autonomous transaction as a process that is called in an outer transaction.
For example, procedure is called by an unknown block,
Procedure write_log (
Code in integer, text in varchar2)
Is
Pragma autonomous_transaction;
Begin
Insert into Log Values (
Code, text,
User, sysdate
);
Commit;
End;
This procedure is used to write logs. logs should be recorded no matter whether the operation is successful or not (that is, whether the unknown block executes rollback. Therefore, we need to write it as an autonomous transaction so that the commit of procedure is independent of the unknown block that calls it, and the log record will not be affected during rollback.