Syntax related to for update in Oracle

Source: Internet
Author: User

The for update syntax in Oracle is purely a select statement: Oracle does not apply any locks, that is, Oracle does not have any restrictions on the data read by the select statement. At this time, another process may be modifying the data in the table, 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. Select statement + for update: Once Oracle finds that this batch of data is being modified, it does not issue this select statement query until the data is modified (commit ), the select statement is automatically executed immediately. If someone needs to modify this batch of data (one or more records) after the query statement is issued, it must wait until the query ends (commit) before modification. This statement is used to lock specific rows (if a where clause exists, it is the rows that meet the where condition ). When these rows are locked, other sessions can select these rows, but they cannot be changed or deleted until the transaction of the statement ends with the commit statement or rollback statement. Select statement + for update NOWAIT: Oracle will change the data tentatively locked, when the data is found to be locked by another session, it will return the error ORA-00054 quickly: resource busy and acquire with NOWAIT specified. Therefore, in the program, we can use nowait to quickly determine whether the current data is locked. If the data is locked, we need to take appropriate business measures for processing. Select statement + for update WAIT n: Same as above. The error ORA-30006: resource busy; acquire with WAIT timeout expired is returned if the resource cannot be obtained after n seconds, instead of returning an exception immediately. Select statement + skip locked: no error is prompted, but no rows selected is returned directly. Select statement + for update of columns: used when multiple tables are connected to the lock, you can specify the tables to be locked. If the columns in the table do not appear after for update, this means that this table is not actually locked. Other users can update the data of these tables. When multiple tables are involved, it plays a major role. If you do not use the column of the specified locked table, the related rows of all tables will be locked, if the column to be modified is specified in of, only the rows of the table associated with these columns will be locked.

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.