Oracle for update skip locked 详解

Article Directory

for update skip locked

in conclusion:

  • Determine whether the record has been locked by other sessions before locking
    • If it is already locked, skip the locked record
    • If there is no lock, then lock the unlocked record

The verification is as follows, the basic data:

SELECT * FROM stu_info t WHERE t.id IN (1, 2);

Insert picture description here

session1:

-- 锁住 id = 1 的所有记录
SELECT * FROM stu_info t WHERE t.id = 1 FOR UPDATE;

Insert picture description here

session2:

-- 锁住 id in (1, 2) 中未被锁定的记录 (跳过已经锁定的记录)
SELECT * FROM stu_info t WHERE t.id IN (1, 2) FOR UPDATE SKIP LOCKED;

Insert picture description here

Guess you like

Origin blog.csdn.net/qq_34745941/article/details/106921793