您的位置:首页 > 其它

for update

2017-04-10 14:22 78 查看
oracle中,当我们使用select for update时,oracle做了2件事。首先对该条记录加锁,然后对该表结构加锁。

For example, if you select a row from a table with the FOR UPDATE clause, two locks will be created. One lock is placed on the row(s) you selected (and this will be an exclusive lock; no one else can lock that specific row in exclusive mode). The other lock,
a ROW SHARE TABLE lock, is placed on the table itself. This will prevent other sessions from placing an exclusive lock on the table and thus prevent them from altering the structure of the table。

1、该记录加锁

select * from hr.employees where employee_id=206 for update;

这个是session 1

看session 2

看以看到session 2 hang了

2、表结构加锁

可以看到session 2修改表结构,hang了


内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签:  oralce