oracle for update 的使用
阿新 • • 發佈:2019-02-04
學習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;