Oracle Database: difference for update and for update nowait of

I. Description

While other transactions to write to the table, wait a period of time or was immediately rejected by the database system and return to Develop ways to search using nowait, so when found in other session data is locked in time, will quickly return ORA-00054 error, the content is the resource is busy, but specifies NOWAIT access to resources in a way. So we can use in a program nowait way to quickly determine whether the current data is locked, if locked in, then we would take appropriate operational measures for processing.

Second, the verification examples

2.1.for update nowait验证

How to understand the above words.

  1. Open a session (that is to open a sqlwindow)
select  empno,ename from emp where empno='7369' for update nowait ;

Results obtained following set:

empno  ename
7369   smith
  1. Open another session
 select  empno,ename from emp where empno='7369' for update nowait ;

Return RA-00054 error, the content is the resource is busy, but the manner specified in NOWAIT access to resources
above sessions are submitted to commit;

2.2.for update verification

  1. Open a session,
 select  empno,ename from emp where empno='7369' for update ;

Results obtained following set:

   empno  ename
    7369    smith
  1. Open another session
select  empno,ename from emp where empno='7369' for update;

Obstruction, does not return an error.
Submitted to the first session, the second answer is performed automatically
submitted to the second session

Third, the summary

3.1.for update

After the last commit or ROLLBACK first session, a second session in the search result is automatically jumped out, and also the data lock stay.
Open a session:

select empno,ename from emp   where empno="7369" for update

Results obtained following set:

empno  ename
7369    smith

Open another session,

update emp set ename='ALLEN'  where empno="7396";

Obstruction.
Submitted to the first session, update statement is executed
and then open a session

update emp set ename="SMITH" where empno='7396';

Also blocked, although the first session since the author released the lock, but the second session update gave the line a lock;

3.2.for update nowait

When you first open a session lock, the second session to run properly. When you run the second session statement, the data has been your second session locked sentence stayed, this time as long as your second session statements have not commit, another session still can not lock the data updates, and more.

Published 19 original articles · won praise 67 · views 20000 +

Guess you like

Origin blog.csdn.net/m1090760001/article/details/104582797