ROLLBACK FAQS

1 What does ROLLBACK do in Oracle

ROLLBACK undoes all uncommitted changes in the current transaction and restores the data to its previous committed state.

2 When does a transaction start and end

A transaction starts with the first DML statement such as INSERT, UPDATE, DELETE, MERGE.
It ends with:

  • COMMIT
  • ROLLBACK
  • Implicit commit for DDL like CREATE, ALTER, DROP, TRUNCATE

3 What is the basic syntax of ROLLBACK

ROLLBACK;

4 Does ROLLBACK release locks

Yes. When you execute ROLLBACK, Oracle releases all row-level locks held by the transaction.

5 Can I rollback after COMMIT

No. Once COMMIT is executed, changes are permanent and cannot be rolled back except via Flashback features if enabled.

6 What is ROLLBACK TO SAVEPOINT

It allows partial undo within a transaction.

Example:

SAVEPOINT sp1;

UPDATE employees SET salary = salary + 1000;

ROLLBACK TO sp1;

Only changes after the savepoint are undone.

7 Does ROLLBACK affect other sessions

No. Other users never see uncommitted changes due to Oracle read consistency.
ROLLBACK simply discards your uncommitted changes.

8 What happens if the session crashes

If a session terminates before commit, Oracle automatically rolls back uncommitted changes during recovery.

9 Does SELECT require ROLLBACK

No. SELECT does not modify data and does not require rollback.

10 Can DDL statements be rolled back

No. DDL statements such as CREATE, DROP, ALTER, TRUNCATE cause an implicit commit before and after execution, so they cannot be rolled back.

11 What happens to savepoints after full rollback

A full ROLLBACK removes all savepoints in the transaction.

12 Can I use ROLLBACK inside PL/SQL

Yes. However:

  • Avoid using COMMIT or ROLLBACK inside reusable procedures unless necessary
  • Let the calling application control the transaction when possible

13 What is the difference between ROLLBACK and ROLLBACK TO SAVEPOINT

ROLLBACK

ROLLBACK TO SAVEPOINT

Undoes entire transaction

Undoes partial transaction

Removes all savepoints

Keeps earlier savepoints

Ends transaction

Does not end transaction

14 Does ROLLBACK impact performance

Large rollbacks may take time because Oracle must undo all changes using undo segments.
Frequent rollbacks in batch processing may indicate poor transaction design.

No comments:

Post a Comment