Oracle row-level locks and table-level locks

Source: Internet
Author: User
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.

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.