Search This Blog

Thursday, February 24, 2022

Oracle / PLSQL: LOCK TABLE Statement

 

Oracle / PLSQL: LOCK TABLE Statement

This Oracle tutorial explains how to use the Oracle LOCK TABLE statement with syntax and examples.

Description

The LOCK TABLE statement is used to lock tables, table partitions, or table subpartitions.

Syntax

The syntax for the LOCK TABLE statement is:

LOCK TABLE tables IN lock_mode MODE [ WAIT [, integer] | NOWAIT ];

Parameters or Arguments

tables
A comma-delimited list of tables.
lock_mode
It is one of the following values:
lock_modeExplanation
ROW SHAREAllows concurrent access to the table, but users are prevented from locking the entire table for exclusive access.
ROW EXCLUSIVEAllows concurrent access to the table, but users are prevented from locking the entire table with exclusive access and locking the table in share mode.
SHARE UPDATEAllows concurrent access to the table, but users are prevented from locking the entire table for exclusive access.
SHAREAllows concurrent queries but users are prevented from updating the locked table.
SHARE ROW EXCLUSIVEUsers can view records in table, but are prevented from updating the table or from locking the table in SHARE mode.
EXCLUSIVEAllows queries on the locked table, but no other activities.
WAIT
It specifies that the database will wait (up to a certain number of seconds as specified by integer) to acquire a DML lock.
NOWAIT
It specifies that the database should not wait for a lock to be released.

Example

Let's look at an example of how to use the LOCK TABLE statement in Oracle.

For example:

LOCK TABLE suppliers IN SHARE MODE NOWAIT;

This example would lock the suppliers table in SHARE MODE and not wait for a lock to be released.

No comments:

Post a Comment

PL/SQL - Collections

A collection is an ordered group of elements having the same data type. Each element is identified by a unique subscript that represents its...