oracle for update 的使用

学习blog地址:http://blog.163.com/m13864039250_1/blog/static/213865248201322252255205/
select xidusn,xidslot,xidsqn,object_id,session_id, oracle_username from v$locked_object;
SELECT * FROM ucf_recharge_trade_order o where o.id='201406211326041011010000006415' for update; -- 锁定 符合条件的一条记录 直到提交事务 下一个请求才能获取到这条记录,并有执行权限
SELECT * FROM ucf_recharge_trade_order o where o.id='201406211326041011010000006415'  for update wait 1;-- 锁定 符合条件的一条记录 等待 1秒,如果1秒没有锁定,报异常
SELECT * FROM ucf_recharge_trade_order o where o.id='201406211326041011010000006415'  for update nowait ;--- 锁定 符合条件的一条记录 不等待 ,锁定失败,立刻报异常
SELECT * FROM ucf_recharge_trade_order o where o.id = 
(select s.order_id from ucf_recharge_trade_suborder s where s.order_id='201406211326041011010000006415') 
for update of o.id;-- 锁定 符合条件的一条记录 通常做关联查询锁定某一条记录 只锁定 o 表中的一条记录

SELECT * FROM ucf_recharge_trade_order o where o.id = 
(select s.order_id from ucf_recharge_trade_suborder s where s.order_id='201406211326041011010000006415') 
for update;-- 锁定两个表的中满足条件的行 

select * from ucf_recharge_trade_suborder s where s.order_id='201406211326041011010000006415';
-- SELECT * FROM ucf_recharge_trade_order o  for update;
-- SELECT * FROM ucf_recharge_trade_order o;
select addr,xidusn,xidslot from v$transaction;
select xidusn,xidslot,xidsqn,object_id,session_id, oracle_username from v$locked_object;

你可能感兴趣的:(oracle for update 的使用)