select for update nowait
nowait的含義很多人都會誤解為“不用等待,立即執行”。但實際上該關鍵字的含義是“不用等待,立即返回”
如果當前請求的資源被其他會話鎖定時,會發生阻塞,nowait可以避免這一阻塞,因為
If
another user is in the process of modifying that row, we will get an
ORA‐00054
Resource Busy error. We are blocked and must wait for the other
user to finish with
it.
可以實驗下,我用pl/sql developer鎖定表game
SQL> select
* from game where game_id =1;
返回一條記錄
SQL> select * from game where game_id=1 for update nowait;
select *
from game where game_id=1 for update nowait
*
ERROR位於第1行:
ORA-00054:資源正忙,要求指定NOWAIT
使用NOWAIT關鍵字,會報ORA‐00054的錯誤
如何來檢視是什麼資源造成這樣的情況呢?並且怎麼解決呢?
檢視鎖定的物件,使用者和會話
SQL> select
lo.oracle_username,do.object_name,s.logon_time,lo.process,s.sid as
s
ession_id
2 from v$locked_object lo,v$session s,dba_objects do
3
where lo.session_id = s.sid and do.object_id = lo.OBJECT_ID
4
/
ORACLE_USERNAME
------------------------------
OBJECT_NAME
--------------------------------------------------------------------------------
LOGON_TIME PROCESS SESSION_ID
------------------- ------------
----------
NBA---使用者名稱稱
GAME---操作的物件
2009-08-04 10:55:15---登入的時間
840:5176 10
使用as sysdba
根據sid檢視具體的sql語句
selectsql_textfromv$session
a,v$sqltext_with_newlines b
whereDECODE(a.sql_hash_value,0, prev_hash_value,
sql_hash_value)=b.hash_value
anda.sid=10;
begin :id :=
sys.dbms_transaction.local_transaction_id; end;
kill session
SQL> select sid,serial# from v$session where sid
=10;
SID SERIAL#
---------- ----------
10
23
SQL> alter system kill session '10,23';
系統已更改。
select * from game where game_id=1 for update nowait;
有資料返回了
當兩個使用者同時更新同一條記錄是, 使用select for update,後執行者,會被阻塞,而使用select for update nowait 則會丟擲:ORA-00054 resource busy and acquire with NOWAIT specified 異常,告之使用者這一行已經鎖定。
來自 “ ITPUB部落格 ” ,連結:http://blog.itpub.net/21416913/viewspace-749557/,如需轉載,請註明出處,否則將追究法律責任。
相關文章
- select for update nowait 與 select for update 區別AI
- 關於 select ... for update 和 for update nowaitAI
- mysql innodb之select for update nowaitMySqlAI
- for update和for update nowaitAI
- FOR UPDATE NOWAIT和 FOR UPDATEAI
- Oracle中的for update 和 for update nowaitOracleAI
- select for update
- oracle select for updateOracle
- SELECT ... FOR UPDATE SKIP LOCKED;
- SQL update select語句SQL
- sql查詢更新update selectSQL
- Oracle中select ... for update的用法Oracle
- Default Locking for INSERT, UPDATE, DELETE, and SELECT ... FOR UPDATE (351)delete
- 深入理解SELECT ... LOCK IN SHARE MODE和SELECT ... FOR UPDATE
- MysqL_select for update鎖詳解MySql
- select for update與autocommit關係MIT
- 使用select監視update的操作
- oracle connection,select,update 工作原理Oracle
- mysql update join,insert select 語法MySql
- UPDATE SET = (SELECT ) 語法的總結
- Oracle中select for update ...一些區別Oracle
- SQLite語句(二):INSERT DELETE UPDATE SELECTSQLitedelete
- 【Mysql】兩條select for update引起的死鎖MySql
- 【MySQL】select for update 的Row Lock 與Table LockMySql
- MySQL中SELECT+UPDATE併發更新問題MySql
- update/select也可能產生buffer busy waits。AI
- DBeaver如何生成select,update,delete,insert語句delete
- 記一次 MySQL select for update 死鎖問題MySql
- 1120 11g select for update skip locked
- MySQL 5.7 SELECT ... LOCK IN SHARE MODE|FOR UPDATE語句說明MySql
- mysql 各種級聯查詢後更新(update select).MySql
- 由select for update鎖等待問題引發的深入思考
- java-Mybatis XML 對映器(select,insert, update 和 delete)JavaMyBatisXMLdelete
- Select for update/lock in share mode 對事務併發性影響
- 檢視慢查詢中,表被update 或 select 次數
- mysql 高併發 select update 併發更新問題解決方案MySql
- QZ面試被問select......for update會鎖表還是鎖行lor面試
- Laravel5.6 如何列印 SQL?insert/update/select 列印方法總結LaravelSQL