Introduction
In Oracle Database, a transaction is a series of SQL statements executed as a single unit of work. To control these transactions, Oracle provides Transaction Control Language (TCL) commands.
These commands are essential for:
- Maintaining data consistency
- Handling success and failure in database operations
- Ensuring reliable application behavior
In this blog, we’ll explain:
- What TCL is
- Why it’s important
- How to use it with clear, practical examples
What Is TCL?
TCL stands for Transaction Control Language.
It helps you control changes made by DML (Data Manipulation Language) operations such as:
Key TCL Commands
Command |
Purpose |
COMMIT |
Save all changes permanently |
ROLLBACK |
Undo uncommitted changes |
SAVEPOINT |
Mark a point to roll back to later |
SET TRANSACTION |
Set transaction properties (optional/advanced) |
1. COMMIT — Save Changes Permanently
The COMMIT command saves all changes made during the current transaction permanently.
Syntax
COMMIT;
Example
INSERT INTO SYSTEM.EMP_IND (empno, ename, nickname, email)
VALUES (11, 'Rithika', 'Rithi', '[email protected]');
COMMIT;
Effect
The new employee record is permanently saved and visible to other users.
2. ROLLBACK — Undo Changes
ROLLBACK undoes changes made during the current transaction, useful when errors occur.
Syntax
ROLLBACK;
Example
DELETE FROM SYSTEM.EMP_IND WHERE empno = 11;
ROLLBACK;
Effect
The deleted employee record is restored.
3. SAVEPOINT — Set Rollback Point
SAVEPOINT marks a point within a transaction. You can roll back to this point without undoing all changes.
Syntax
SAVEPOINT savepoint_name;
Example
UPDATE SYSTEM.EMP_IND SET ename = 'Rithi R' WHERE empno = 11;
SAVEPOINT update_done;
DELETE FROM SYSTEM.EMP_IND WHERE empno = 11;
ROLLBACK TO update_done;
Effect
Only the DELETE is undone. The update remains.
4. SET TRANSACTION — Configure Transaction (Advanced)
SET TRANSACTION allows you to configure transaction behavior, such as read-only mode.
Syntax
SET TRANSACTION READ ONLY;
Example Use Case
- Prevent unintended writes during reporting or analytics queries.
Summary Table of TCL Commands
Command |
Description |
Effect |
COMMI |
Save changes permanently |
Makes DML changes permanent |
ROLLBACK |
Undo changes since the last commit |
Cancels uncommitted changes |
SAVEPOINT |
Set rollback point inside a transaction |
Allows partial rollback |
ROLLBACK TO |
Roll back to a savepoint |
Reverts changes after savepoint |
SET TRANSACTION |
Advanced transaction settings (optional) |
Controls isolation, read-only, etc. |
Why TCL Matters in Real Applications
In enterprise software development, proper transaction control is critical:
Scenario |
Importance of TCL |
Bank Transfers |
Commit only after both debit & credit succeed |
Online Orders |
Rollback if payment or inventory update fails |
Batch Processing |
Use SAVEPOINT to undo specific steps selectively |
Without TCL, your app risks data corruption or inconsistent states.
Conclusion
Understanding and using TCL commands in Oracle Database ensures:
- Data consistency
- Safe error handling
- Efficient multi-user transaction management
Whether you're working on banking apps, e-commerce platforms, or enterprise systems, mastering TCL helps you build reliable and fault-tolerant applications.