Oracle 21c FOR UPDATEで指定テーブルのレコードをロックする方法

環境
Windows 11 Pro 21H2 64bit
Oracle Database 21c Express Edition Release 21.0.0.0.0

書式
FOR UPDATE
[ OF 表.列名 ]
OF句
表を結合する場合に使用し、表とその列名を指定します。
OF句で指定した表のSELECTしたレコードがロックされますが、OF句で指定してない表はロックされません。

使用例
表「user」のSELECTレコードのみロックし、表「info」のSELECTレコードはロックしない。
SELECT時にロックがかかっていた場合は、ロックが開放されるまで待機します。

SQL構文

Plain text
Copy to clipboard
Open code in new window
EnlighterJS 3 Syntax Highlighter
select
t1.ucd
, t2.dcd
, t1.name
from
user t1
, info t2
where
t1.dcd = t2.dcd for update of t1.ucd;
select t1.ucd , t2.dcd , t1.name from user t1 , info t2 where t1.dcd = t2.dcd for update of t1.ucd;
select
    t1.ucd
  , t2.dcd
  , t1.name 
from
    user t1
  , info t2 
where
  t1.dcd = t2.dcd for update of t1.ucd;

 

Oracle 21c

Posted by arkgame