Oracle for update and for update nowait

Source: Internet
Author: User

Original address: http://www.cnblogs.com/quanweiru/archive/2012/11/09/2762223.html

1 . The difference between for update and for update nowait:

First of all, if only Select,Oracle will not add any lock, that is, Oracle to Select read the data there is no limit, although it is possible that another process is modifying the data in the table, And the result of the modification may affect the result of your current SELECT statement, but because there is no lock, the Select result is the state recorded in the current timetable.

If a for update is added, Oracle will not issue the SELECT statement query until the data is modified (commit) once it discovers that the batch of data is being modified (which matches the query criteria), and this is done automatically immediately. SELECT statement.

Similarly, if a query statement is issued, someone needs to modify the batch of data (one or more of them), and it must wait until the end of the query (commit) before it can be modified.

The for update nowait and for update will lock the result set that is queried, unlike if another thread is modifying the data in the result set, the forupdate nowait does not wait for the resource. As soon as you find that some data in the result set is locked, you immediately return "ORA-00054 error, content is the resource is busy , but specifies to get the resource NOWAIT".

the for update and for update nowait are added with a row-level lock, which means that only data that meets the where condition is locked. If you only use the UPDATE statement to change the data, it may not be locked up and not respond, inexplicably wait, but if before, the forupdate NOWAIT statement will change the data to be tentatively locked, It can be understood by the error prompt to return immediately, perhaps this is the meaning of for update and nowait.

After testing, for update or for update nowait query Lock, in the result set of SELECT, as long as any one record in the lock, then the entire result set is waiting for system resources (if it is nowait, throws a corresponding exception)

2.for update nowait and for update purposes :
Locks all rows of the table, rejecting other writes against the table. Ensures that only the current transaction writes to the specified table.
differences between for update nowait and for update:

When another transaction is going to write to the table, it waits for some time or immediately to be rejected by the database system . The NoWait method is used for retrieval, so when the data is found to be locked by another session, it is returned quickly. ORA-00054 error, content is the resource is busy , but specifies to get the resource in NOWAIT way. So in the program we can use the NoWait method to quickly determine whether the current data is locked, if locked, it is necessary to take appropriate business measures to deal with.  

Oracle for update and for update nowait

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.