Home > Database > Mysql Tutorial > body text

Oracle 行级锁与表级锁

WBOY
Release: 2016-06-07 17:11:03
Original
989 people have browsed it

Oracle 行级锁与表级锁,如果该行记录已经被锁定,更新的时候等待5秒,如果这5秒内,该行记录被解锁,那么返回查询结果,如果5秒

一、行级锁:
(下面这句将给该表的所有行都加上锁)
select * from person for update;

如果该行记录已经被锁定,就不用等待,系统会直接抛错 ora-00054
select * from person  where id = '1'  for update nowait

如果该行记录已经被锁定,更新的时候等待5秒,如果这5秒内,该行记录被解锁,那么返回查询结果,如果5秒内仍未解锁,那么系统会直接抛错 ora-00054
select * from person for update wait 5;

另外,如果使用 select * from person  where id = '1'  for update ,当该行记录已经被锁定时,,那么系统将一直等待该行记录被释放后,再加锁。

二、表级锁:

行共享:允许用户进行任何操作,禁止排他锁
lock table person in row share mode;

行排他:允许用户进行任何操作,禁止共享锁
lock table person in row exclusive mode;

共享锁:其他用户只能看,不能修改
lock table person in share mode;

共享行排他:比共享锁有更多限制
lock table person in share row exclusive mode;

排他锁:其他用户只能看,不能修改,不能加其他锁
lock table person in exclusive mode;

对于通过lock table命令主动添加的锁定来说,如果要释放它们,只需要发出rollback命令即可。

linux

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!