Добавил:
Upload Опубликованный материал нарушает ваши авторские права? Сообщите нам.
Вуз: Предмет: Файл:
Semestr2 / 1 - Oracle / Oracle selected docs / SQL reference.pdf
Скачиваний:
24
Добавлен:
12.05.2015
Размер:
11.92 Mб
Скачать

ROLLBACK

ROLLBACK

Purpose

Use the ROLLBACK statement to undo work done in the current transaction, or to manually undo the work done by an in-doubt distributed transaction.

Note: Oracle recommends that you explicitly end transactions in application programs using either a COMMIT or ROLLBACK statement. If you do not explicitly commit the transaction and the program terminates abnormally, then Oracle rolls back the last uncommitted transaction.

See Also:

Oracle9i Database Concepts for information on transactions

Oracle9i Heterogeneous Connectivity Administrator’s Guide for information on distributed transactions

SET TRANSACTION on page 18-50 for information on setting characteristics of the current transaction

COMMIT on page 12-75

SAVEPOINT on page 18-2

Prerequisites

To roll back your current transaction, no privileges are necessary.

To manually roll back an in-doubt distributed transaction that you originally committed, you must have the FORCE TRANSACTION system privilege. To manually roll back an in-doubt distributed transaction originally committed by another user, you must have the FORCE ANY TRANSACTION system privilege.

SQL Statements: DROP SEQUENCE to ROLLBACK 17-99

ROLLBACK

Syntax

rollback::=

 

 

SAVEPOINT

 

 

TO

 

 

savepoint

WORK

FORCE

text

ROLLBACK

 

 

 

;

Semantics

WORK

The keyword WORK is optional and is provided for ANSI compatibility.

TO SAVEPOINT Clause

Specify the savepoint to which you want to roll back the current transaction. If you omit this clause, then the ROLLBACK statement rolls back the entire transaction.

Using ROLLBACK without the TO SAVEPOINT clause performs the following operations:

Ends the transaction

Undoes all changes in the current transaction

Erases all savepoints in the transaction

Releases the transaction’s locks

See Also: SAVEPOINT on page 18-2

Using ROLLBACK with the TO SAVEPOINT clause performs the following operations:

Rolls back just the portion of the transaction after the savepoint.

Erases all savepoints created after that savepoint. The named savepoint is retained, so you can roll back to the same savepoint multiple times. Prior savepoints are also retained.

Releases all table and row locks acquired since the savepoint. Other transactions that have requested access to rows locked after the savepoint must continue to wait until the transaction is committed or rolled back. Other transactions that

17-100 Oracle9i SQL Reference

ROLLBACK

have not already requested the rows can request and access the rows immediately.

Restrictions on In-doubt Transactions You cannot manually roll back an in-doubt transaction to a savepoint.

FORCE Clause

Specify FORCE to manually roll back an in-doubt distributed transaction. The transaction is identified by the ’text’ containing its local or global transaction ID. To find the IDs of such transactions, query the data dictionary view DBA_2PC_ PENDING.

A ROLLBACK statement with a FORCE clause rolls back only the specified transaction. Such a statement does not affect your current transaction.

Restriction on Forcing Rollback ROLLBACK statements with the FORCE clause are not supported in PL/SQL.

See Also: Oracle9i Heterogeneous Connectivity Administrator’s Guide for more information on distributed transactions and rolling back in-doubt transactions

Examples

Rolling Back Transactions: Examples The following statement rolls back your entire current transaction:

ROLLBACK;

The following statement rolls back your current transaction to savepoint banda_ sal:

ROLLBACK TO SAVEPOINT banda_sal;

See Also: "Creating Savepoints: Example" on page 18-2 for a full version of this example

The following statement manually rolls back an in-doubt distributed transaction:

ROLLBACK WORK

FORCE ’25.32.87’;

SQL Statements: DROP SEQUENCE to ROLLBACK 17-101

ROLLBACK

17-102 Oracle9i SQL Reference

Соседние файлы в папке Oracle selected docs