for update uncommitted lead to lock table

select for update is in order at the time of the query to avoid other users to the table insert, modify, or delete operation, causing inconsistency of the table.

Scenario:

When do I need to use for update? That is, those who need the business level data exclusivity, consider using for update. When on the scene, such as booking tickets, stamps displayed on the screen, while the real carried out the ticket, the need to redefine what this data has not been modified by other clients. Therefore, in this confirmation process can be used for update. This program is a unified solution to the problem, need to be prepared early.

When we carry out the operation for update, select the ordinary there is a big difference. Generally select is not necessary to consider whether the data is locked up to read the previous version of the multi-version read consistency properties. After adding for update, Oracle requires to start a new transaction, try to lock the data. If the current has been locked, the default behavior is to block waiting for the inevitable. Use role nowait clause is to avoid waits, discovery request when the resource is locked when the lock is not released directly return an error.
In daily life, we use for update is quite common, especially in such as pl / sql developer manually modify the data. At this time, just find it convenient, while the true meaning for update lack of understanding.
For update statement is a special case of the manual lock to improve the level and scope of Oracle. Oracle's locking mechanism is the various types of database lock mechanism in relatively good. Therefore, Oracle does not need to consider the general user and application control and direct lift lock. Even think of such a deadlock scenario appears lock-related issues, mostly related to manual lifting lock. Therefore, Oracle is not recommended for update as a daily use development. Moreover, in the normal development and operation and maintenance, but forgot to use for update submitted, it will cause a lot of table lock failure.

A few examples:
After select * from t for update row lock will wait for the release, return query results. This will usually wait after submission, will unlock.
select * from t for update nowait does not wait for the line to release the lock, the lock prompts conflict, does not return results
select * from t for update wait 5 wait five seconds, if the trip has not yet released the lock, the lock prompts conflict, does not return a result
select * from t for update skip locked query return query results, but ignores the record row lock 

SELECT ... fOR UPDATE statement syntax is as follows: 
  SELECT ... fOR UPDATE [oF column_list] [the n-WAIT | NOWAIT] [SKIP lOCKED]; 
which : 
  oF clause specifies the columns will be updated, that target specific column on the line. 
  WAIT clause specifies wait for another user to release the lock of seconds, to prevent an indefinite wait.

Advantage "Use FOR UPDATE WAIT" clause as follows: 
  1 prevent wait indefinitely locked row; 
  2 allows the application of more control wait time locks.
  3 very useful for interactive applications, because users can not wait for these uncertain 
  4 If you use a skip locked, the lock can cross the line, does not report triggered by the wait n 'resource busy' exception reporting

 

 

 

 

Original Address: https: //www.cnblogs.com/xiyubaby/p/4623516.html

Guess you like

Origin www.cnblogs.com/cuitang/p/12171119.html