select * from table_name for update; 和 select t.*, t.rowid from table_name t的区别

select * from table_name for update; 和 select t.*, t.rowid from table_name t 的区别

前者会对你查询出来的结果加上锁,而后者就没有这样的机制;

此时如果有另一个session过来去对你结果集中的数据进行更新或者删除操作,则需要等到第一个事务提交或者回滚后,才能够执行该语句;

例如:

create table temp_yaosht(col1 varchar2(32));

insert into temp_yaosht values('a');

insert into temp_yaosht values('b');

insert into temp_yaosht values('c');

insert into temp_yaosht values('d');

insert into temp_yaosht values('e');

第一个session的sql语句

select  * 

   from temp_yaosht

where col1 in ('a','b','c') for update;

第二session的sql语句

update temp_yaosht

     set col1='aa'

where col1='a';

第三session的sql语句

update temp_yaosht

     set col1='dd'

where col1='d';

先执行第一个sql语句;然后当我们执行第二个sql的时候,会发现sql一直处于执行状态,只有当第一个sql的事务提交之后,第二个sql才会执行,且结束。

第三个sql的执行并不受影响,因为第一个sql的只对‘a’,'b','c'这三条记录加了锁,而不是对该表加的锁。


select t.*, t.rowid from table_name t 则没有这样的限制。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值