In the recent use of Oracle, if the concurrent state inserts data will result in duplication of data, the need to use Oracle lock mechanism, the following is a common Oracle lock table method.
First, row-level locks:
(The following sentence will lock all rows of the table)
SELECT * from person for update;
If the row record has been locked, there is no need to wait, and the system will simply throw the wrong ora-00054
SELECT * FROM person WHERE id = ' 1 ' for update nowait
If the row record has been locked, the update is waiting for 5 seconds, if this row record is unlocked within 5 seconds, then return query results, if not unlocked within 5 seconds, then the system will directly throw the wrong ora-00054
SELECT * FROM person to update wait 5;
Additionally, if the select * from person where ID is used = ' 1 ' for update, when the row record is locked, the system waits for the row record to be freed and then locked.
Second, table-level locks:
Row sharing: Allow users to do anything to prohibit exclusive locks
Lock table person in row share mode;
Line Exclusive: Allow users to do anything to prevent shared locks
Lock table person in row exclusive mode;
Shared locks: Other users can only see, can not modify
Lock table person in share mode;
Shared row Exclusive: More restrictions than shared locks
Lock table person in share row exclusive mode;
Exclusive Lock: Other users can only see, can not modify, can not add other locks
Lock table person in exclusive mode;
For locks that are actively added through the Lock Table command, you only need to issue the rollback command if you want to release them.