Oracle8i SQL Reference
Release 2 (8.1.6)

A76989-01

Library

Product

Contents

Index

Prev Up Next

SQL Statements (continued), 2 of 5


SET TRANSACTION

Syntax


Purpose

To establish the current transaction as a read-only or read-write, establish its isolation level, or assign it to a specified rollback segment.

The operations performed by a SET TRANSACTION statement affect only your current transaction, not other users or other transactions. Your transaction ends whenever you issue a COMMIT or ROLLBACK statement. Oracle implicitly commits the current transaction before and after executing a data definition language (DDL) statement.

See Also:

"COMMIT" and "ROLLBACK"

Prerequisites

If you use a SET TRANSACTION statement, it must be the first statement in your transaction. However, a transaction need not have a SET TRANSACTION statement.

Keywords and Parameters

READ ONLY 

establishes the current transaction as a read-only transaction. This clause established transaction-level read consistency.

See Also: Oracle8i Concepts. 

 

All subsequent queries in that transaction only see changes committed before the transaction began. Read-only transactions are useful for reports that run multiple queries against one or more tables while other users update these same tables.  

 

Restriction: Only the following statements are permitted in a read-only transaction:

  • subqueries (that is, SELECT statements without the for_update_clause)

  • LOCK TABLE

  • SET ROLE

  • ALTER SESSION

  • ALTER SYSTEM

 

READ WRITE 

establishes the current transaction as a read-write transaction. This clause established statement-level read consistency, which is the default. 

 

Restriction: You cannot toggle between transaction-level and statement-level read consistency in the same transaction. 

ISOLATION LEVEL  

specifies how transactions containing database modifications are handled.  

 

SERIALIZABLE 

specifies serializable transaction isolation mode as defined in SQL92. If a serializable transaction contains data manipulation language (DML) that attempts to update any resource that may have been updated in a transaction uncommitted at the start of the serializable transaction, then the DML statement fails.  

 

 

Note: The COMPATIBLE initialization parameter must be set to 7.3.0 or higher for SERIALIZABLE mode to work. 

 

READ COMMITTED 

is the default Oracle transaction behavior. If the transaction contains DML that requires row locks held by another transaction, then the DML statement waits until the row locks are released. 

USE ROLLBACK SEGMENT 

assigns the current transaction to the specified rollback segment. This clause also implicitly establishes the transaction as a read-write transaction. 

 

This clause lets you to assign transactions of different types to rollback segments of different sizes. For example:

  • If no long-running queries are concurrently reading the same tables, you can assign small transactions to small rollback segments, which are more likely to remain in memory.

  • You can assign transactions that modify tables that are concurrently being read by long-running queries to large rollback segments, so that the rollback information needed for the read-consistent queries is not overwritten.

  • You can assign transactions that insert, update, or delete large amounts of data to rollback segments large enough to hold the rollback information for the transaction.

 

 

You cannot use the READ ONLY clause and the USE ROLLBACK SEGMENT clause in a single SET TRANSACTION statement or in different statements in the same transaction. Read-only transactions do not generate rollback information and therefore are not assigned rollback segments.  

Examples

The following statements could be run at midnight of the last day of every month to count how many ships and containers the company owns. This report would not be affected by any other user who might be adding or removing ships and/or containers.

COMMIT; 
SET TRANSACTION READ ONLY; 
SELECT COUNT(*) FROM ship; 
SELECT COUNT(*) FROM container; 
COMMIT; 

The last COMMIT statement does not actually make permanent any changes to the database. It simply ends the read-only transaction.

The following statement assigns your current transaction to the rollback segment OLTP_5:

SET TRANSACTION USE ROLLBACK SEGMENT oltp_5; 

Prev Up Next
Oracle
Copyright © 1999 Oracle Corporation.

All Rights Reserved.

Library

Product

Contents

Index