---
description: What are TCL Statements in PL/SQL? TCL stands for Transaction Control Statements. It will either save the pending transactions or roll back the pending transaction. These statements play the vital rol
title: Autonomous Transaction in Oracle PL/SQL
image: https://www.guru99.com/images/autonomous-transaction-in-oracle-plsql.png
---

 

[Skip to content](#main) 

**⚡ Smart Summary**

Transaction Control Statements in Oracle PL/SQL, namely COMMIT, ROLLBACK, and SAVEPOINT, decide whether pending DML changes are saved or discarded. An autonomous transaction runs as an independent subprogram that commits or rolls back separately from the main transaction.

* 💾 **COMMIT:** Makes all pending DML changes permanent, ends the transaction, releases locks, and erases every savepoint.
* ↩️ **ROLLBACK:** Undoes pending changes, either the whole transaction or back to a named SAVEPOINT.
* 📌 **SAVEPOINT:** Marks a point inside a transaction so a later ROLLBACK TO can undo only part of the work.
* 🔀 **Autonomous Transaction:** The PRAGMA AUTONOMOUS\_TRANSACTION directive lets a subprogram commit or roll back on its own.
* 🧾 **Use Cases:** Autonomous transactions suit audit and error logging that must persist even if the main work rolls back.
* 🤖 **AI Assistance:** AI assistants such as GitHub Copilot draft COMMIT, ROLLBACK, and PRAGMA blocks and flag missing commits.

[ Read More ](javascript:void%280%29;) 

![Autonomous Transaction in Oracle PL/SQL with COMMIT and ROLLBACK](https://www.guru99.com/images/autonomous-transaction-in-oracle-plsql.png)

## What are TCL Statements in PL/SQL?

TCL stands for Transaction Control Statements. These statements either save the pending transactions or roll back the pending transactions. They play a vital role, because unless a transaction is saved, the changes made through [DML statements](https://www.guru99.com/sql-pl-sql.html) will not be stored permanently in the database. Below are the different TCL statements in [PL/SQL](https://www.guru99.com/pl-sql-tutorials.html).

| Statement   | Description                                                                  |
| ----------- | ---------------------------------------------------------------------------- |
| COMMIT      | Saves all the pending transactions.                                          |
| ROLLBACK    | Discards all the pending transactions.                                       |
| SAVEPOINT   | Creates a point in the transaction up to which a rollback can be done later. |
| ROLLBACK TO | Discards all the pending transactions up to the specified savepoint.         |

The transaction will be complete under the following scenarios:

* When any of the above statements is issued (except SAVEPOINT).
* When DDL statements are issued (DDL are auto-commit statements).
* When DCL statements are issued (DCL are auto-commit statements).

## Using SAVEPOINT and ROLLBACK TO

The table above introduces SAVEPOINT and ROLLBACK TO, and together they give you partial control over a transaction. A SAVEPOINT marks a named point inside the current transaction. A later ROLLBACK TO that savepoint undoes every change made after it, while keeping the work done before it intact.

This is useful when a long transaction performs several [SQL](https://www.guru99.com/sql.html) steps and only the last step fails. Instead of discarding the entire transaction, you can roll back to the last good savepoint and continue.

**Syntax:**

SAVEPOINT <savepoint_name>;
   -- one or more DML statements
ROLLBACK TO <savepoint_name>;

Key points to remember about savepoints:

* A SAVEPOINT exists only inside the current transaction; a COMMIT or a full ROLLBACK erases every savepoint.
* When you roll back to a savepoint, any savepoints created after it are erased, but the savepoint you roll back to is kept.
* ROLLBACK TO does not end the transaction; the changes made before the savepoint stay pending until you COMMIT or ROLLBACK.
* If you reuse a savepoint name, the newer SAVEPOINT moves the marker to the later position.

Because ROLLBACK TO leaves the transaction open, you still decide at the end whether to COMMIT the remaining changes or discard them with a full ROLLBACK.

## What is Autonomous Transaction

In PL/SQL, all the modifications done on data are termed a transaction. A transaction is considered complete when a save or discard is applied to it. If no save or discard is given, then the transaction is not considered complete, and the modifications done on the data will not be made permanent on the server.

By default, PL/SQL treats all the modifications during a session as a single transaction, and saving or discarding that transaction affects every pending change in the session. An autonomous transaction provides the developer with the ability to make changes in a separate transaction and to save or discard that particular transaction without affecting the main session transaction.

* An autonomous transaction can be specified at the subprogram level.
* To make any [subprogram](https://www.guru99.com/subprograms-procedures-functions-pl-sql.html) work in a different transaction, the keyword PRAGMA AUTONOMOUS\_TRANSACTION should be given in the declarative section of that block.
* It instructs the compiler to treat this as a separate transaction, and saving or discarding inside this block will not reflect in the main transaction.
* Issuing COMMIT or ROLLBACK is mandatory before leaving this autonomous transaction and returning to the main transaction, because at any time only one transaction can be active.
* So once an autonomous transaction is started, it must be saved and completed before control can move back to the main transaction.

**Syntax:**

DECLARE
PRAGMA AUTONOMOUS_TRANSACTION;
.
BEGIN
<execution_part>
[COMMIT|ROLLBACK]
END;
/

In the above syntax, the block has been made an autonomous transaction.

### RELATED ARTICLES

* [PL/SQL Block: Structure, Syntax & Anonymous Example ](https://www.guru99.com/blocks-pl-sql.html "PL/SQL Block: Structure, Syntax & Anonymous Example")
* [Oracle PL/SQL Object Types: CREATE TYPE with Examples ](https://www.guru99.com/object-types-pl-sql.html "Oracle PL/SQL Object Types: CREATE TYPE with Examples")
* [Oracle PL/SQL FOR LOOP with Example ](https://www.guru99.com/oracle-plsql-for-loop.html "Oracle PL/SQL FOR LOOP with Example")
* [While Loop in Oracle PL/SQL with Example ](https://www.guru99.com/oracle-plsql-while-loop.html "While Loop in Oracle PL/SQL with Example")

**Example 1:** In this example, we are going to understand how an autonomous transaction works.

The screenshot below shows this autonomous transaction example and its output in Oracle.

[![Autonomous transaction example committing a nested block while the main transaction rolls back in Oracle PL/SQL](https://www.guru99.com/images/PL-SQL/110215_1042_SQLinPLSQL17.png)](https://www.guru99.com/images/PL-SQL/110215%5F1042%5FSQLinPLSQL17.png)

DECLARE
   l_salary   NUMBER;
   PROCEDURE nested_block IS
   PRAGMA autonomous_transaction;
    BEGIN
     UPDATE emp
       SET salary = salary + 15000
       WHERE emp_no = 1002;
   COMMIT;
   END;
BEGIN
   SELECT salary INTO l_salary FROM emp WHERE emp_no = 1001;
   dbms_output.put_line('Before Salary of 1001 is'|| l_salary);
   SELECT salary INTO l_salary FROM emp WHERE emp_no = 1002;
   dbms_output.put_line('Before Salary of 1002 is'|| l_salary);    
   UPDATE emp 
   SET salary = salary + 5000 
   WHERE emp_no = 1001;

nested_block;
ROLLBACK;

 SELECT salary INTO  l_salary FROM emp WHERE emp_no = 1001;
 dbms_output.put_line('After Salary of 1001 is'|| l_salary);
 SELECT salary INTO l_salary FROM emp WHERE emp_no = 1002;
 dbms_output.put_line('After Salary of 1002 is '|| l_salary);
end;

**Output**

Before:Salary of 1001 is 15000 
Before:Salary of 1002 is 10000 
After:Salary of 1001 is 15000 
After:Salary of 1002 is 25000

**Code Explanation:**

* **Code line 2:** Declaring l\_salary as NUMBER.
* **Code line 3:** Declaring the nested\_block procedure.
* **Code line 4:** Making the nested\_block procedure an AUTONOMOUS\_TRANSACTION.
* **Code line 7-9:** Increasing the salary for employee number 1002 by 15000.
* **Code line 10:** Committing the autonomous transaction.
* **Code line 13-16:** Printing the salary details of employees 1001 and 1002 before the changes.
* **Code line 17-19:** Increasing the salary for employee number 1001 by 5000.
* **Code line 20:** Calling the nested\_block procedure.
* **Code line 21:** Discarding the main transaction.
* **Code line 22-25:** Printing the salary details of employees 1001 and 1002 after the changes.

The salary increase for employee number 1001 is not reflected because the main transaction has been discarded. The salary increase for employee number 1002 is reflected because that block has been made a separate transaction and saved at the end.

So irrespective of the save or discard at the main transaction, the changes in the autonomous transaction are saved without affecting the main transaction.

## When to Use Autonomous Transactions

Autonomous transactions are powerful, so it helps to know when they fit. Reserve them for work that must succeed or fail independently of the main transaction, not for core business logic. Common use cases include:

* **Audit logging:** Record who changed sensitive data, when, and the old and new values, so the log survives even if the main transaction rolls back.
* **Error logging:** Write an error record inside an [exception](https://www.guru99.com/exception-handling-pl-sql.html) handler and COMMIT it, so the diagnostic detail is kept while the failed transaction is discarded.
* **Counters and statistics:** Advance a usage counter or hit count that must persist regardless of the caller’s outcome.
* **COMMIT inside a trigger:** A trigger cannot issue COMMIT directly; an autonomous transaction is the only supported way to do so.

Avoid autonomous transactions for ordinary updates that should share the fate of the main transaction. Overusing them can hide data behind independent commits and make debugging harder. As a rule, every autonomous block must end with an explicit COMMIT or ROLLBACK.

## Autonomous vs Regular Transactions

The difference between a regular (main) transaction and an autonomous transaction comes down to scope and independence. The table below compares them.

| Aspect                    | Regular Transaction                 | Autonomous Transaction                                    |
| ------------------------- | ----------------------------------- | --------------------------------------------------------- |
| Scope                     | Shares one session transaction      | Runs as a separate child transaction                      |
| COMMIT / ROLLBACK effect  | Affects all pending session changes | Affects only the autonomous block                         |
| Declaration               | Default behaviour                   | PRAGMA AUTONOMOUS\_TRANSACTION in the declarative section |
| Effect of parent rollback | Changes are lost                    | Committed autonomous changes are kept                     |
| Typical use               | Core business logic                 | Audit and error logging                                   |

Unlike a regular [nested block](https://www.guru99.com/nested-blocks-pl-sql.html), whose changes always share the outcome of the enclosing transaction, an autonomous block stands on its own. Understanding this difference helps you decide when a block should be independent and when it should share the result of the main transaction.

## FAQs

🔒 What error occurs if an autonomous transaction ends without COMMIT or ROLLBACK?

Oracle raises ORA-06519 and rolls back the autonomous work. Every autonomous transaction must finish with an explicit COMMIT or ROLLBACK before control returns to the main transaction, because only one active transaction is allowed at a time.

🔁 Can you use COMMIT or ROLLBACK inside a database trigger?

Not directly. A normal trigger cannot issue COMMIT or ROLLBACK. Declaring the trigger, or a procedure it calls, with PRAGMA AUTONOMOUS\_TRANSACTION lets it commit its own changes independently of the statement that fired the trigger.

🧩 Can an autonomous transaction see the parent transaction’s uncommitted changes?

No. Once the parent is suspended, the autonomous transaction runs independently and cannot see the parent’s uncommitted changes. It sees only data already committed in the database, so waiting on a parent lock can cause a deadlock.

⚙️ Does a DDL statement automatically commit the current transaction?

Yes. Every DDL statement, such as CREATE, ALTER, or DROP, issues an implicit COMMIT before and after it runs. Any pending DML in the session is committed automatically, so a DDL statement cannot be rolled back afterward.

🪜 How many autonomous transactions can be active at the same time?

An autonomous block can call another, and each manages its own COMMIT or ROLLBACK. Oracle caps how many transactions are active at once through the TRANSACTIONS initialization parameter, so very deep nesting of autonomous blocks can fail.

↩️ Can you roll back changes after a COMMIT?

No. A COMMIT makes changes permanent, releases locks, and erases savepoints, so it cannot be undone with ROLLBACK. To reverse committed data you must run new DML. Use SAVEPOINT and ROLLBACK TO for partial undo before committing.

🤖 Can GitHub Copilot generate COMMIT, ROLLBACK, and autonomous transaction code?

Yes. [GitHub Copilot](https://github.com/features/copilot) drafts COMMIT and ROLLBACK logic, SAVEPOINT blocks, and PRAGMA AUTONOMOUS\_TRANSACTION procedures from a comment. Review the commit placement and error handling, since a misplaced commit can corrupt transaction boundaries.

🧠 How does AI help review transaction control in PL/SQL?

AI assistants scan procedures for missing or misplaced COMMIT and ROLLBACK statements, commits inside loops, and unclosed autonomous blocks. This machine-learning review flags transaction bugs and suggests safer boundaries before the code reaches production.

#### Summarize this post with:

ChatGPT Perplexity Grok Google AI 

**Stay Updated on AI** **Get Weekly AI Skills, Trends, Actionable Advice.** 

##### Sign up for the newsletter

Subscribe for Free 

You have successfully subscribed.  
Please check your inbox. 

![AI-Newsletter](https://www.guru99.com/images/footer-email-avatar-imges-1.png) Chosen by over **350,000+** professionals 

[Scroll to top ](#wrapper)Scroll to top 

× 

Toggle Menu Close 

Search for: 

Search

```json
{"@context":"https://schema.org","@graph":[{"@type":"Organization","@id":"https://www.guru99.com/#organization","name":"Guru99","sameAs":["https://www.facebook.com/Guru99Official","https://twitter.com/guru99com"],"logo":{"@type":"ImageObject","@id":"https://www.guru99.com/#logo","url":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","contentUrl":"https://www.guru99.com/images/guru99-logo-v1-150x59.png","caption":"Guru99","inLanguage":"en-US"}},{"@type":"WebSite","@id":"https://www.guru99.com/#website","url":"https://www.guru99.com","name":"Guru99","publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US"},{"@type":"ImageObject","@id":"https://www.guru99.com/images/autonomous-transaction-in-oracle-plsql.png","url":"https://www.guru99.com/images/autonomous-transaction-in-oracle-plsql.png","width":"700","height":"250","caption":"Autonomous Transaction in Oracle PL/SQL","inLanguage":"en-US"},{"@type":"BreadcrumbList","@id":"https://www.guru99.com/pl-sql-tcl-statements.html#breadcrumb","itemListElement":[{"@type":"ListItem","position":"1","item":{"@id":"https://www.guru99.com","name":"Home"}},{"@type":"ListItem","position":"2","item":{"@id":"https://www.guru99.com/pl-sql","name":"PL-SQL"}},{"@type":"ListItem","position":"3","item":{"@id":"https://www.guru99.com/pl-sql-tcl-statements.html","name":"Autonomous Transaction in Oracle PL/SQL"}}]},{"@type":"WebPage","@id":"https://www.guru99.com/pl-sql-tcl-statements.html#webpage","url":"https://www.guru99.com/pl-sql-tcl-statements.html","name":"Autonomous Transaction in Oracle PL/SQL","dateModified":"2026-07-22T17:34:47+05:30","isPartOf":{"@id":"https://www.guru99.com/#website"},"primaryImageOfPage":{"@id":"https://www.guru99.com/images/autonomous-transaction-in-oracle-plsql.png"},"inLanguage":"en-US","breadcrumb":{"@id":"https://www.guru99.com/pl-sql-tcl-statements.html#breadcrumb"}},{"@type":"Person","@id":"https://www.guru99.com/author/fiona","name":"Fiona Brown","description":"I'm Fiona brown, a Full Stack Developer with over a decade of experience, sharing practical guides on robust and scalable application development.","url":"https://www.guru99.com/author/fiona","image":{"@type":"ImageObject","@id":"https://www.guru99.com/images/fiona-brown-author.png","url":"https://www.guru99.com/images/fiona-brown-author.png","caption":"Fiona Brown","inLanguage":"en-US"},"worksFor":{"@id":"https://www.guru99.com/#organization"}},{"articleSection":"PL-SQL","headline":"Autonomous Transaction in Oracle PL/SQL","description":"What are TCL Statements in PL/SQL? TCL stands for Transaction Control Statements. It will either save the pending transactions or roll back the pending transaction. These statements play the vital rol","keywords":"pl-sql","speakable":{"@type":"SpeakableSpecification","cssSelector":[".entry-title",".summary"]},"@type":"Article","author":{"@id":"https://www.guru99.com/author/fiona","name":"Fiona Brown"},"dateModified":"2026-07-22T17:34:47+05:30","image":{"@id":"https://www.guru99.com/images/autonomous-transaction-in-oracle-plsql.png"},"copyrightYear":"2026","name":"Autonomous Transaction in Oracle PL/SQL","subjectOf":[{"@type":"FAQPage","mainEntity":[{"@type":"Question","name":"What error occurs if an autonomous transaction ends without COMMIT or ROLLBACK?","acceptedAnswer":{"@type":"Answer","text":"Oracle raises ORA-06519 and rolls back the autonomous work. Every autonomous transaction must finish with an explicit COMMIT or ROLLBACK before control returns to the main transaction, because only one active transaction is allowed at a time."}},{"@type":"Question","name":"Can you use COMMIT or ROLLBACK inside a database trigger?","acceptedAnswer":{"@type":"Answer","text":"Not directly. A normal trigger cannot issue COMMIT or ROLLBACK. Declaring the trigger, or a procedure it calls, with PRAGMA AUTONOMOUS_TRANSACTION lets it commit its own changes independently of the statement that fired the trigger."}},{"@type":"Question","name":"Can an autonomous transaction see the parent transaction's uncommitted changes?","acceptedAnswer":{"@type":"Answer","text":"No. Once the parent is suspended, the autonomous transaction runs independently and cannot see the parent's uncommitted changes. It sees only data already committed in the database, so waiting on a parent lock can cause a deadlock."}},{"@type":"Question","name":"Does a DDL statement automatically commit the current transaction?","acceptedAnswer":{"@type":"Answer","text":"Yes. Every DDL statement, such as CREATE, ALTER, or DROP, issues an implicit COMMIT before and after it runs. Any pending DML in the session is committed automatically, so a DDL statement cannot be rolled back afterward."}},{"@type":"Question","name":"How many autonomous transactions can be active at the same time?","acceptedAnswer":{"@type":"Answer","text":"An autonomous block can call another, and each manages its own COMMIT or ROLLBACK. Oracle caps how many transactions are active at once through the TRANSACTIONS initialization parameter, so very deep nesting of autonomous blocks can fail."}},{"@type":"Question","name":"Can you roll back changes after a COMMIT?","acceptedAnswer":{"@type":"Answer","text":"No. A COMMIT makes changes permanent, releases locks, and erases savepoints, so it cannot be undone with ROLLBACK. To reverse committed data you must run new DML. Use SAVEPOINT and ROLLBACK TO for partial undo before committing."}},{"@type":"Question","name":"Can GitHub Copilot generate COMMIT, ROLLBACK, and autonomous transaction code?","acceptedAnswer":{"@type":"Answer","text":"Yes. GitHub Copilot drafts COMMIT and ROLLBACK logic, SAVEPOINT blocks, and PRAGMA AUTONOMOUS_TRANSACTION procedures from a comment. Review the commit placement and error handling, since a misplaced commit can corrupt transaction boundaries."}},{"@type":"Question","name":"How does AI help review transaction control in PL/SQL?","acceptedAnswer":{"@type":"Answer","text":"AI assistants scan procedures for missing or misplaced COMMIT and ROLLBACK statements, commits inside loops, and unclosed autonomous blocks. This machine-learning review flags transaction bugs and suggests safer boundaries before the code reaches production."}}]}],"@id":"https://www.guru99.com/pl-sql-tcl-statements.html#schema-1149152","isPartOf":{"@id":"https://www.guru99.com/pl-sql-tcl-statements.html#webpage"},"publisher":{"@id":"https://www.guru99.com/#organization"},"inLanguage":"en-US","mainEntityOfPage":{"@id":"https://www.guru99.com/pl-sql-tcl-statements.html#webpage"}}]}
```
