Oracle row-level lock and table-level lock ____oracle

Source: Internet
Author: User

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.

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.