代码改变世界

select * from tab where ..... for update nowait

2012-12-09 01:28  Rollen Holt  阅读(677)  评论(0编辑  收藏  举报
大家在使用plsqldeveloper时 ,修改数据的时候比较喜欢 select * from tab for update ,然后开始修改数据
这种模式比较容易锁住数据,有的时候还出现自己锁住自己的事情(自己有开了个窗口用了select * from tab for update )
我个人推荐大家在修改数据的时候用 select * from tab where ..... for update nowait; 大家都用这个,否则效果会打折扣。
例子:
下图如果两个人都使用 select * from tab for update ,那么必定有一个人被锁住

select <wbr>* <wbr>from <wbr>tab <wbr>where <wbr>..... <wbr>for <wbr>update <wbr>nowait

只有一方commit后,另一方才能用,如图2
select <wbr>* <wbr>from <wbr>tab <wbr>where <wbr>..... <wbr>for <wbr>update <wbr>nowait

如果用select * from tab where ..... for update nowait; ,会直接报错(ora-00054),而不会锁住,避免了自己锁定自己,同时也告诉别人这个数据我在改了,请您等等再该
select <wbr>* <wbr>from <wbr>tab <wbr>where <wbr>..... <wbr>for <wbr>update <wbr>nowait

原文地址:http://blog.sina.com.cn/s/blog_4ea0bbed0100vhvz.html