Oracle row-level locks and table-level locks. If the row record has been locked, wait for 5 seconds for updates. If the row record is unlocked within these 5 seconds, the query result is returned, if 5 seconds
Oracle row-level locks and table-level locks. If the row record has been locked, wait for 5 seconds for updates. If the row record is unlocked within these 5 seconds, the query result is returned, if 5 seconds
1. Row-Level Lock:
(The following statement adds a lock to all rows in the table)
Select * from person for update;
If this row of record is locked, the system directly throws an error ora-00054 without waiting
Select * from person where id = '1' for update nowait
If the record of this row is locked and the record is updated for 5 seconds, if the record is unlocked within the 5 seconds, the query result is returned. If the record is not unlocked within the 5 seconds, then the system will directly throw the wrong ora-00054
Select * from person for update wait 5;
In addition, if you use select * from person where id = '1' for update, when this row of records has been locked, the system will wait until the row record is released and then lock again.
Ii. Table-Level Lock:
Row sharing: allows users to perform any operation and disallow exclusive locks.
Lock table person in row share mode;
Exclusive row: allow users to perform any operation and prohibit shared locks
Lock table person in row exclusive mode;
Shared lock: other users can only view and cannot modify
Lock table person in share mode;
Exclusive shared rows: more limits than shared locks
Lock table person in share row exclusive mode;
Exclusive lock: other users can only view, cannot modify, and cannot add other locks
Lock table person in exclusive mode;
For the locks that are automatically added using the lock table command, if you want to release them, you only need to issue the rollback command.