Chapter 5 COMMIT and ROLLBACK TCL
Chapter 5 COMMIT and ROLLBACK TCL
What is a Transaction?
A transaction is a set of SQL statements which Oracle treats as a Single Unit. i.e. all the statements
should execute successfully or none of the statements should execute.
To control transactions Oracle does not made permanent any DML statements unless you commit it.
If you don’t commit the transaction and power goes off or system crashes then the transaction is roll
backed.
COMMIT
To make the changes done in a transaction permanent issue the COMMIT statement.
WORK is optional.
COMMENT is also optional, specify this if you want to identify this transaction in data dictionary
DBA_2PC_PENDING.
Example
commit;
ROLLBACK
To rollback the changes done in a transaction give rollback statement. Rollback restore the state of
the database to the last commit point.
Example :
SAVEPOINT
Specify a point in a transaction to which later you can roll back.
Example
rollback to a;
Then row from salgrade table and dept will be roll backed. At this point you can commit the row
inserted into emp table or rollback the transaction.
If you give
rollback to b;
Then row inserted into salgrade table will be roll backed. At this point you can commit the row
inserted into dept table and emp table or rollback to savepoint a or completely roll backed the
transaction.
If you give
rollback;
commit;
Then the whole transaction is committed and all savepoints are removed.