Oracle8i SQL Reference
Release 2 (8.1.6)

A76989-01

Library

Product

Contents

Index

Prev Up Next

SQL Statements (continued), 6 of 8


LOCK TABLE

Syntax


Purpose

To lock one or more tables (or table partitions or subpartitions) in a specified mode. This lock manually overrides automatic locking and permits or denies access to a table or view by other users for the duration of your operation.

Some forms of locks can be placed on the same table at the same time. Other locks allow only one lock per table. For a complete description of the interaction of lock modes, see Oracle8i Concepts.

A locked table remains locked until you either commit your transaction or roll it back, either entirely or to a savepoint before you locked the table.

A lock never prevents other users from querying the table. A query never places a lock on a table. Readers never block writers and writers never block readers.

See Also:

"COMMIT", "ROLLBACK", and "SAVEPOINT"

Prerequisites

The table or view must be in your own schema or you must have the LOCK ANY TABLE system privilege, or you must have any object privilege on the table or view.

Keywords and Parameters

schema  

is the schema containing the table or view. If you omit schema, Oracle assumes the table or view is in your own schema.  

table / view  

is the name of the table to be locked. If you specify view, Oracle locks the view's base tables.

If you specify PARTITION (partition) or SUBPARTITION (subpartition), Oracle first acquires an implicit lock on the table. The table lock is the same as the lock you specify for partition or subpartition, with two exceptions:

  • If you specify a SHARE lock for the subpartition, Oracle acquires an implicit ROW SHARE lock on the table.

  • If you specify an EXCLUSIVE lock for the subpartition, Oracle acquires an implicit ROW EXCLUSIVE lock on the table.

If you specify PARTITION and table is composite-partitioned, then Oracle acquires locks on all the subpartitions of partition

dblink  

is a database link to a remote Oracle database where the table or view is located. For information on specifying database links, see "Referring to Objects in Remote Databases". You can lock tables and views on a remote database only if you are using Oracle's distributed functionality. All tables locked by a LOCK TABLE statement must be on the same database.  

 

If you omit dblink, Oracle assumes the table or view is on the local database.  

lockmode  

is one of the following:

ROW SHARE allows concurrent access to the locked table, but prohibits users from locking the entire table for exclusive access. ROW SHARE is synonymous with SHARE UPDATE, which is included for compatibility with earlier versions of Oracle.

ROW EXCLUSIVE is the same as ROW SHARE, but also prohibits locking in SHARE mode. Row Exclusive locks are automatically obtained when updating, inserting, or deleting.

SHARE UPDATE--see ROW SHARE.

SHARE allows concurrent queries but prohibits updates to the locked table.

SHARE ROW EXCLUSIVE is used to look at a whole table and to allow others to look at rows in the table but to prohibit others from locking the table in SHARE mode or updating rows.

EXCLUSIVE allows queries on the locked table but prohibits any other activity on it.  

NOWAIT  

specifies that Oracle returns control to you immediately if the specified table (or specified partition or subpartition) is already locked by another user. In this case, Oracle returns a message indicating that the table, partition, or subpartition is already locked by another user.  

 

If you omit this clause, Oracle waits until the table is available, locks it, and returns control to you.  

Examples

The following statement locks the EMP table in exclusive mode, but does not wait if another user already has locked the table:

LOCK TABLE emp 

IN EXCLUSIVE MODE 
NOWAIT; 

The following statement locks the remote ACCOUNTS table that is accessible through the database link BOSTON:

LOCK TABLE accounts@boston 

IN SHARE MODE;

Prev Up Next
Oracle
Copyright © 1999 Oracle Corporation.

All Rights Reserved.

Library

Product

Contents

Index