LOCK TABLE Statement

 

Manually lock one or more tables.

Syntax:

   LOCK TABLE [schema.] table [options] IN lockmode MODE [NOWAIT]

LOCK TABLE [schema.] view [options] IN lockmode MODE [NOWAIT]

Options:
PARTITION (partition)
SUBPARTITION (subpartition)
@dblink

lockmodes:
EXCLUSIVE
SHARE
ROW EXCLUSIVE
SHARE ROW EXCLUSIVE
ROW SHARE* | SHARE UPDATE*

If NOWAIT is omitted Oracle will wait until the table is available.

Several tables can be locked with a single command - separate with commas

e.g. LOCK TABLE table1,table2,table3 IN ROW EXCLUSIVE MODE;

Default Locking Behaviour

A pure SELECT will not lock any rows.

INSERT, UPDATE or DELETE's - will place a ROW EXCLUSIVE lock.

SELECT...FROM...FOR UPDATE NOWAIT - will place a ROW EXCLUSIVE lock.

Multiple Locks on the same rows with LOCK TABLE

Even when a row is locked you can always perform a SELECT (because SELECT does not lock any rows) in addition to this, each type of lock will allow additional locks to be granted as follows.

ROW SHARE = Allow ROW EXCLUSIVE or ROW SHARE or SHARE locks to be granted to the locked rows.

ROW EXCLUSIVE = Allow ROW EXCLUSIVE or ROW SHARE locks to be granted to the locked rows.

SHARE ROW EXCLUSIVE = Allow ROW SHARE locks to be granted to the locked rows.

SHARE = Allow ROW SHARE or SHARE locks to be granted to the locked rows.

EXCLUSIVE = Allow SELECT queries only

Although it is valid to place more than one lock on a row, UPDATES and DELETE's may still cause a wait if a conflicting row lock is held by another transaction.

* = Oracle 6 option included for compatibility

Related Commands:

COMMIT
DELETE

INSERT
ROLLBACK
SELECT

UPDATE
DBMS_LOCK

Related Views:

DBA_ALL_TABLES       ALL_ALL_TABLES       USER_ALL_TABLES
DBA_TABLES           ALL_TABLES           USER_TABLES       TAB
DICTIONARY
DICT_COLUMNS
V$LOCK
V$_LOCK
V$LOCKED_OBJECT
V$LOCKS_WITH_COLLISIONS
V$LOCK_ACTIVITY
V$LOCK_ELEMENT

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值