Sub topic 5
Implicit commits: DDL, normal exit, and abnormal termination
Assume you know SELECT, INSERT, UPDATE, DELETE, and basic Oracle connections. This chapter focuses on transaction boundaries that happen without an explicit COMMIT or ROLLBACK.
An implicit commit is a commit caused by Oracle or by the client program. It can make earlier changes permanent before you expect it. The safest rule is to treat transaction-ending events as part of your database design.
DDL commits before and after
Data definition language (DDL) changes the database structure. Examples include CREATE TABLE, ALTER TABLE, DROP TABLE, and TRUNCATE.
Oracle commits the current transaction before executing a DDL statement. If the DDL succeeds, Oracle also commits after executing it. Therefore, DDL can commit unrelated data changes:
CREATE TABLE accounts (
id NUMBER PRIMARY KEY,
owner VARCHAR2(50) NOT NULL,
balance NUMBER(12,2) NOT NULL CHECK (balance >= 0)
);
INSERT INTO accounts (id, owner, balance)
VALUES (1, 'Alice', 1000);
CREATE TABLE scratch_table (x NUMBER);
ROLLBACK;
SELECT owner
FROM accounts
WHERE id = 1;The ROLLBACK cannot remove Alice's row. The CREATE TABLE committed the insert before it ran.
The same rule applies if the DDL statement fails: the transaction was committed before Oracle attempted the DDL. A successful DDL statement then commits its own structural change as well.
Some tools also issue commits for commands that manage permissions or sessions. Check the tool's behavior instead of assuming that only visible COMMIT statements matter.
Normal and abnormal program exit
A client program controls what happens when a connection ends normally. Many clients commit when you use their normal exit command. For example, SQL*Plus commonly treats EXIT as a commit unless you specify otherwise:
INSERT INTO accounts (id, owner, balance)
VALUES (2, 'Bob', 200);
EXIT ROLLBACK;Here, the insert is discarded. An application may instead commit, roll back, or require the application code to decide. SQL Developer and other graphical tools may show a prompt or use connection settings.
An abnormal termination is different. If a process or connection ends unexpectedly, Oracle normally rolls back its uncommitted transaction. This protects the database from exposing incomplete work. It does not undo changes that were already committed.
| Situation | Typical result for uncommitted work |
|---|---|
| Explicit `COMMIT` | Changes become permanent |
| DDL statement | Current transaction commits before DDL |
| Normal client exit | Depends on the client or exit option |
| Abnormal connection loss | Oracle rolls back uncommitted work |
Practical rule
Keep transaction boundaries explicit in application code. Commit after one complete business operation, and roll back in error-handling code. Never rely on closing a window, ending a script, or losing a connection to decide whether important work is saved.
Exercise
An UPDATE is followed by ALTER TABLE, and the session then runs ROLLBACK. Will the update be undone?
Show answer
No. Oracle commits the open transaction before executing the DDL, so the update is already permanent.