You can put the autonomous transaction pragma anywhere in the declaration section of your PL/SQL block. The best option, however, would be to place it before any datastructure declarations. That way, anyone reading your code will immediately identify the program as an autonomous transaction.This pragma is the only syntax change made to PL/SQL to support autonomoustransactions. COMMIT, ROLLBACK, the DML statements—all the rest is as it was before. However, these statements have a different scope of impact and visibility whenexecuted within an autonomous transaction, and you will have to include a COMMIT or ROLLBACK in your program.
The AUTONOMOUS_TRANSACTION pragma instructs the PL/SQL compiler to mark a routine as autonomous (independent).
An autonomous transaction is anindependent transaction started by another transaction, the main transaction .Autonomous transactions let you suspend the main transaction, do SQL operations,commit or roll back those operations, then resume the main transaction.
Usage NotesIn this context, the term routine includes
Top-level (not nested) anonymous PL/SQL blocks
Local, standalone, and packaged functions and procedures
Methods of a SQL object type
Database triggersYou cannot use the pragma to mark all subprograms in a package (or all methods in anobject type) as autonomous. Only individual routines can be marked autonomous. Youcan code the pragma anywhere in the declarative section of a routine. But, for readability,code the pragma at the top of the section.Once started, an autonomous transaction is fully independent. It shares no locks,resources, or commit-dependencies with the main transaction. So, you can log events,increment retry counters, and so on, even if the main transaction rolls back.
Unlike regular triggers, autonomous triggers can contain transaction controlstatements such as COMMIT and ROLLBACK. Also, unlike regular triggers,autonomous triggers can execute DDL statements (such as CREATE and DROP)using native dynamic SQL.
Changes made by an autonomous transaction become visible to other transactions whenthe autonomous transaction commits. The changes also become visible to the maintransaction when it resumes, but only if its isolation level is set to READ COMMITTED(the default).2