Your browser does not support JavaScript. This help page requires JavaScript to render correctly. Rolling Back Transactions
Skip Headers
Previous
Previous
 
Next
Next

Rolling Back Transactions

Rolling back a transaction undoes its changes. You can roll back the entire current transaction, or you can roll it back only to a specified savepoint.

To roll back the current transaction only to a specified savepoint, you must use the ROLLBACK statement with the TO SAVEPOINT clause.

To roll back the entire current transaction, use either the ROLLBACK statement without the TO SAVEPOINT clause, or (in the SQL Developer environment) the Rollback Changes icon.

Rolling back the entire current transaction:

Rolling back the current transaction only to the specified savepoint:

To see the effect of a rollback in SQL Developer, you might have to click the Refresh icon.

As a result of the example in About the INSERT Statement, the REGIONS table has a region called 'Middle East and Africa' and a region called 'Africa'. The following example corrects this problem (a very simple transaction) and checks the change, but then rolls back the transaction and then checks the rollback.

Rolling Back an Entire Transaction

Before transaction:

SELECT * FROM REGIONS
ORDER BY REGION_ID;
 

Result:

 REGION_ID REGION_NAME
---------- -------------------------
         1 Europe
         2 Americas
         3 Asia
         4 Middle East and Africa
         5 Africa

Transaction (change table):

UPDATE REGIONS
SET REGION_NAME = 'Middle East'
WHERE REGION_NAME = 'Middle East and Africa';

Result:

1 row updated.
 

Check change:

SELECT * FROM REGIONS
ORDER BY REGION_ID;
 

Result:

 REGION_ID REGION_NAME
---------- -------------------------
         1 Europe
         2 Americas
         3 Asia
         4 Middle East
         5 Africa

Roll back transaction:

ROLLBACK;

Result:

Rollback complete.

Check rollback:

SELECT * FROM REGIONS
ORDER BY REGION_ID;
 

Result:

 REGION_ID REGION_NAME
---------- -------------------------
         1 Europe
         2 Americas
         3 Asia
         4 Middle East and Africa
         5 Africa

Related Topics

Oracle Database SQL Language Reference

About DML Statements and Transactions