EDUCBA

EDUCBA

MENUMENU
  • Free Tutorials
  • Free Courses
  • Certification Courses
  • 360+ Courses All in One Bundle
  • Login
Home Data Science Data Science Tutorials Oracle Tutorial Oracle LOCK TABLE
Secondary Sidebar
Oracle Tutorial
  • Advanced
    • Timestamp to Date in Oracle
    • Oracle Golden Gate
    • Oracle Virtual Machine
    • Oracle Describe Table
    • Oracle Clauses
    • Oracle Having Clause
    • Oracle?Primavera
    • Oracle FOREIGN Key
    • PIVOT in Oracle
    • Oracle Alter Table
    • Oracle Queries
    • Oracle Views
    • Oracle Window Functions
    • Oracle String Functions
    • Oracle Date Functions
    • Oracle Analytic Functions
    • Oracle Aggregate Functions
    • Select in Oracle
    • INSERT in Oracle
    • DISTINCT in Oracle
    • Function in Oracle
    • Oracle GROUP_CONCAT
    • Oracle INSTR()
    • Oracle CONVERT
    • Oracle LENGTH()
    • Oracle EXISTS
    • Oracle REPLACE()
    • Oracle MERGE
    • Oracle LEAD()
    • Oracle EXTRACT()
    • Oracle LISTAGG()
    • Oracle SYS_CONTEXT()
    • Oracle COALESCE
    • Oracle NVL()
    • Oracle SYSDATE()
    • Oracle?Date Format
    • Oracle SYS_GUID()
    • Oracle WILDCARDS
    • Oracle Synonyms
    • Oracle Subquery
    • BETWEEN in Oracle
    • FETCH in Oracle
    • Oracle Index
    • Oracle Function-based Index
    • Oracle UNIQUE Index
    • Oracle Bitmap Index
    • Oracle Column
    • Oracle Triggers
    • Oracle Procedures
    • Sample Database for Oracle
    • Oracle LIKE Operator
    • ORDER BY in Oracle
    • Oracle ORDER BY DESC
    • GROUP BY in Oracle
    • Oracle GROUP BY HAVING
    • Oracle Aliases
    • Table in Oracle
    • Oracle Temporary Table
    • Oracle? Table Partition
    • Oracle rename table
    • Oracle CTE
    • Cursor in Oracle
    • Oracle LOCK TABLE
    • Oracle Tablespace
    • Oracle CARDINALITY
    • Oracle REGEXP
    • Oracle REGEXP_REPLACE
    • Oracle to_date
    • JSON in Oracle
    • Oracle COMMIT
    • Oracle GRANT
    • Oracle MD5
    • Oracle ROLLBACK
    • Oracle Users
    • Oracle TIMESTAMP
    • IF THEN ELSE in Oracle
    • Oracle While Loop
    • Oracle Clone Database
    • Oracle Backup Database
    • Oracle? XML
    • Oracle XMLAGG
    • Oracle XMLTABLE
    • Oracle Performance Tuning
    • Oracle B Tree Index
    • Oracle fusion
    • Oracle ebs
    • Oracle GRC
    • Oracle ERP
    • Oracle ASM
    • Oracle Cloud
    • Oracle HCM Cloud
    • Oracle Integration Cloud
    • Oracle Jinitiator
    • Oracle pathfinder
    • Oracle VirtualBox
    • Oracle Weblogic Server
    • Oracle decode
    • Oracle Exadata
    • Oracle ZFS
    • Oracle? utilities
    • JDBC Driver for Oracle
    • Oracle? DBA Versions
    • Oracle DBA Salary
  • Basic
    • Oracle Marketing Cloud
    • What is Oracle?
    • Career in Oracle
    • How to Install Oracle
    • Oracle Versions
    • What Is Oracle Database
    • Oracle Data Warehousing
    • Oracle Warehouse Builder
    • Career In Oracle Database Administrator
    • Career In Oracle DBA
    • What is Oracle RAC
    • Oracle DBA
    • Oracle? Vanderbilt
    • What is RMAN Oracle
    • Oracle Database Administration
    • Oracle Operators
    • Oracle Constraints
    • Oracle number
    • Oracle Data Types
    • Oracle UNIQUE Constraint
    • Oracle Check Constraint
  • Joins
    • Joins in Oracle
    • Inner Join in Oracle
    • Oracle Cross Join
    • Left Join in Oracle
    • OUTER Join in Oracle
    • Oracle Full Outer Join
    • Natural Join in Oracle
    • Oracle Self Join
    • Oracle hash join
    • Oracle? Update with Join
  • Oracle SET Operators
    • UNION in Oracle
    • Oracle UNION ALL
    • INTERSECT in Oracle
    • MINUS in Oracle
  • Interview Questions
    • Oracle Interview Questions
    • Oracle Apps Interview Questions
    • Oracle Apps Technical Interview Questions
    • Oracle Database Interview Questions
    • Oracle Forms Interview Questions
    • Oracle PL/SQL Interview Questions
    • Oracle RAC Interview Questions
    • Oracle SOA Interview Questions

Related Courses

Oracle Course Training

Oracle DBA Certification Course

MongoDB Certification Training

Oracle LOCK TABLE

By Priya PedamkarPriya Pedamkar

Oracle LOCK TABLE

Introduction to Oracle LOCK TABLE

Lock Table in Oracle can be defined as a statement which can be used to lock one or more tables, table partitions or even table sub partitions which explicitly as when we use this statement basically overrides the automatic locking feature already present in the oracle and locks the table or tables in a specified mode as defined by the user which means the user can permit or deny certain operations on the locked table to other users for the duration of the user’s operation.

Syntax:

Given below is the syntax of Oracle Lock table:

LOCK TABLE table_name IN lock_mode MODE [WAIT | NOWAIT ];

Start Your Free Data Science Course

Hadoop, Data Science, Statistics & others

Parameters:

  • table_name: It refers to the name of the table.
  • Lock_mode: It refers to the mode on which we are going to lock the table. There are many modes.
  • ROW_SHARE: This mode allows concurrent access to the table in which it is applied. Here concurrent access means that it allows multiple users to access the table simultaneously and the users who are accessing the table are not allowed to lock the entire table which means no exclusive access.
  • ROW_EXCLUSIVE: This mode is just like the above allows concurrent access to the table. It means multiple users can access it simultaneously and the users who are accessing the table are not allowed to lock the entire table. The difference of this mode with ROW_SHARE is that it also does not allow locking in share mode.
  • SHARE UPDATE: It is similar like ROW_SHARE. It allows concurrent access to the table. It allows multiple user access to the table. It does not allow users to lock the entire table.
  • SHARE: It is similar to SHARE UPDATE. It allows concurrent access to the table. It allows multiple user access to the table. It does not allow users to lock the entire table. It also prohibits updates to the locked table.
  • SHARE ROW EXCLUSIVE: This mode allows Users to view records in the table but it does not allow the users to update the table or from locking the table in SHARE mode.
  • EXCLUSIVE: This mode allows only queries to be executed on the Locked table. No other activities are allowed other than that.
  • WAIT: This keyword when used allows the database to wait until the table is available and then lock the table and returns the control to the user.
  • NOWAIT: This condition refers to the condition when the database does not wait for the lock to be released. This is useful when the user wants the database to return control to him/her immediately.

How LOCK TABLE Statement works in Oracle?

  • When we use LOCK Table statement and after it gets executed the database overrides the manual automatic locking available in Oracle and permits or denies other users to view or update the table for a specified time as mentioned in the statement.
  • The permission actually depends on the type of mode of Lock that the user has chosen.
  • In case suppose the user has chosen the mode EXCLUSIVE then other users can only use queries on that table and the database will not allow any update on that table from other users.
  • In case it is ROW SHARE mode then the database will not allow the user to lock the whole table and will allow concurrent access to the table.
  • The duration of time is also specified in the statement or queries itself.
  • So, it actually depend on the type of mode u provide to the database and depending on that the database will lock your table or tables.

Examples of Oracle LOCK TABLE

Given below are the examples mentioned:

Example #1

EXCLUSIVE MODE WITH NO WAIT.

Here we will look at the Exclusive mode of operation. We will lock the table employee in the Exclusive mode with NO WAIT which means that it will not wait if another user has already locked the table.

Code:

LOCK TABLE employee
IN EXCLUSIVE MODE NOWAIT;

Output:

Oracle LOCK TABLE 1

As we can see in the output screenshot the output says that Lock succeeded which means that the employee is successfully locked in Exclusive mode.

All in One Data Science Bundle(360+ Courses, 50+ projects)
Python TutorialMachine LearningAWSArtificial Intelligence
TableauR ProgrammingPowerBIDeep Learning
Price
View Courses
360+ Online Courses | 50+ projects | 1500+ Hours | Verifiable Certificates | Lifetime Access
4.7 (86,408 ratings)

Example #2

SHARE MODE WITH NO WAIT.

In this case, we will slightly change the situation we will issue a lock on the employee table present in the database in SHARE MODE with NO WAIT. One important point to note is that once the share lock is obtained, exclusive locks cannot be obtained. NO WAIT means that it will not wait for a lock to be released.

Code:

LOCK TABLE employee
IN SHARE MODE NOWAIT;

Output:

SHARE MODE WITH NO WAIT

As per the screenshot, we can see that the SHARE lock has been successfully obtained on the Employee table.

Example #3

EXCLUSIVE MODE WITH WAIT.

In this example, we will look at the Exclusive mode of operation. We will lock the table employee in the Exclusive mode with WAIT which means that the database will wait until the table is available and then lock the table.

Code:

LOCK TABLE employee
IN EXCLUSIVE MODE WAIT 5;

In the above query, the wait time is mentioned as 5 seconds.

Output:

Oracle LOCK TABLE 3

As per the screenshot, we can see the lock was successfully obtained.

Conclusion

In this article, we saw the definition of the LOCK TABLE statement and its syntax. We also saw the various modes of LOCK available and how they work. To get a better understanding we also went through a few examples.

Recommended Articles

This is a guide to Oracle LOCK TABLE. Here we discuss the introduction to Oracle LOCK TABLE along with the working and examples respectively. You may also have a look at the following articles to learn more –

  1. Oracle COMMIT 
  2. Cursor in Oracle
  3. Career In Oracle DBA
  4. What is RMAN Oracle?
Popular Course in this category
Oracle Training (14 Courses, 8+ Projects)
  14 Online Courses |  8 Hands-on Projects |  120+ Hours |  Verifiable Certificate of Completion
4.5
Price

View Course

Related Courses

Oracle DBA Database Management System Training (2 Courses)4.9
All in One Financial Analyst Bundle- 250+ Courses, 40+ Projects4.8
0 Shares
Share
Tweet
Share
Primary Sidebar
Footer
About Us
  • Blog
  • Who is EDUCBA?
  • Sign Up
  • Live Classes
  • Corporate Training
  • Certificate from Top Institutions
  • Contact Us
  • Verifiable Certificate
  • Reviews
  • Terms and Conditions
  • Privacy Policy
  •  
Apps
  • iPhone & iPad
  • Android
Resources
  • Free Courses
  • Database Management
  • Machine Learning
  • All Tutorials
Certification Courses
  • All Courses
  • Data Science Course - All in One Bundle
  • Machine Learning Course
  • Hadoop Certification Training
  • Cloud Computing Training Course
  • R Programming Course
  • AWS Training Course
  • SAS Training Course

ISO 10004:2018 & ISO 9001:2015 Certified

© 2022 - EDUCBA. ALL RIGHTS RESERVED. THE CERTIFICATION NAMES ARE THE TRADEMARKS OF THEIR RESPECTIVE OWNERS.

EDUCBA
Free Data Science Course

SPSS, Data visualization with Python, Matplotlib Library, Seaborn Package

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA Login

Forgot Password?

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA
Free Data Science Course

Hadoop, Data Science, Statistics & others

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

EDUCBA

*Please provide your correct email id. Login details for this Free course will be emailed to you

By signing up, you agree to our Terms of Use and Privacy Policy.

Let’s Get Started

By signing up, you agree to our Terms of Use and Privacy Policy.

This website or its third-party tools use cookies, which are necessary to its functioning and required to achieve the purposes illustrated in the cookie policy. By closing this banner, scrolling this page, clicking a link or continuing to browse otherwise, you agree to our Privacy Policy

Loading . . .
Quiz
Question:

Answer:

Quiz Result
Total QuestionsCorrect AnswersWrong AnswersPercentage

Explore 1000+ varieties of Mock tests View more