LOCK - Types - Levels
LOCK - Types - Levels
Locks
Definition :
Locks are mechanism used to ensure data integrity. The oracle engine automatically
locks table data while executing SQL statements like Select/insert/UPDATE/DELETE. This
type of locking is called implicit locking
Types of Locks
There are two types of Locks
Shared Lock
Exclusive Lock
Shared Lock
Shared locks are placed on resources whenever a read operation (select) is performed.
Multiple shared locks can be simultaneously set on a resource.
Exclusive Locks
Exclusive locks are placed on resources whenever a write operation (INSERT, UPDATE
And DELETE) are performed.
Only one exclusive lock can be placed on a resource at a time.
i.e. the first user who acquires an exclusive lock will continue to have the sole
ownership of the resource, and no other user can acquire an exclusive lock on that
resource
Levels of Locks
Oracle does not provide a field level lock.
Oracle provides the following three levels of Locking.
Row Level
Page Level
Table Level
Row Level Locking
If the WHERE clause evaluates to only one row in the table, a row level lock is used.
Page Level Locking
If the WHERE clause evaluates to a set of data, a page level lock is used.
Table Level Locking
If there is no WHERE clause, the query accesses the entire table, a table level lock is
used.
Can't update entire table data when update is done by other user.
Syntax: LOCK TABLE <table name> [<table name>]….. IN { ROW SHARE / ROW EXCLUSIVE /
SHARE UPDATE / SHARE / SHARE ROW EXCLUSIVE / EXCLUSIVE }[NOWAIT]
Exclusive: They allow query on the locked resource but prohibit any other activity
Syntax: Client A > Lock table client_master IN Exclusive Mode NOWAIT;
Output Table(s) Locked.