Differences between for update and UPDATE NOWAIT

Source: Internet
Author: User

The difference between for update and update nowait is the first point. If it is only a select statement, Oracle will not apply any locks, that is, Oracle will not impose any restrictions on the data read by the select statement. Www.2cto.com although another process may be modifying the data in the table at this time, and the modification result may affect the results of your current select statement, but because there is no lock, therefore, the select result is the status recorded in the current timetable. If for update is added, Oracle will not issue this select statement query once it finds that the data (which meets the query conditions) is being modified until the data is modified (commit ), the select statement is automatically executed immediately. Similarly, if someone needs to modify this batch of data (one or several records) after the query statement is issued, it must wait until the query ends (commit. Both www.2cto.com for update nowait and for update lock the queried result set. The difference is that if another thread is modifying the data in the result set, for update nowait does not wait for resources, as long as some data in the result set is found to be locked, immediately return "ORA-00054 error, content is the resource is busy, but specify to get the resource in NOWAIT mode ". PS: for update and for update nowait are added with a row-Level Lock, that is, only data that meets the where condition is locked. If you only use the update statement to change the data, it may be because the lock is not added and there is no response, inexplicably waiting, but if before this, for update nowait statement, you can tentatively lock the data to be changed, and then you can understand the truth through the error prompt returned immediately. Maybe this is the meaning of for update and NOWAIT. After testing, the query locks are performed in the for update or for update nowait mode. In the select result set, if any record is locked, the entire result set is waiting for system resources (if nowait is used, an exception is thrown ). When multiple tables are associated with the query, you can use the for update of clause to determine the specific table with row locking. CURSOR c1 is select last_name, department_name FROM employees, deployments WHERE employees. department_id = parameters. department_id AND job_id = 'sa _ Man' for update of salary; a session in sqldeveloper is an SQL window

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.