Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium


How to Lock a table or record in the Oracle using query

Posted on 2005-04-15
Medium Priority
Last Modified: 2012-06-21
Hi friends
 I want to lock the table using the query in oracle so can any body tell how I will do the same  I know  how to lock the table in SQLServer  as

begin transaction
update <table> set <field>=<value> where <condition>
This will lock the table. You can open another query analyzer window/session in sqlserver, and run a select * from <table>, it will block.

the same thing i want to do in oracle so can anybody tell me how I can do this in oracle

Question by:vvs
LVL 22

Accepted Solution

Helena Marková earned 200 total points
ID: 13789251
The Oracle locking mechanism is different from SQL Server one. You can read this documentation - the registration is free:

Expert Comment

by:Pierrick LOUBIER
ID: 13789267
LVL 11

Expert Comment

ID: 13789877
like "select * from emp where deptno = 20 for update; " will lock all the rows with DEPTNO=20. This lock can be released by either issuing a COMMIT or ROLLBACK. You can also use "for update of ename" or "for update NOWAIT". Issue the lock before using UPDATE/DELETE statement.
LVL 25

Expert Comment

ID: 13794337
I don't believe there is any way to get Oracle to do that.  The approrpiate way to lock would be

lock table {table_name} in exclusive mode;

However, this will only prevent changes...a query against the table is still possible.  Oracle ensures consistent reads, and doesn't prevent locks from giving you a consistent view to the data.

Author Comment

ID: 13823177
ya I am accepting the answer here for Oracle can any one tell me the sme for Db2
I mean how I can lock the table in db2

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Instead of error trapping or hard-coding for non-updateable fields when using QODBC, let VBA automatically disable them when forms open. This way, users can view but not change the data. Part 1 explained how to use schema tables to do this. Part 2 h…
How much do you know about the future of data centers? If you're like 50% of organizations, then it's probably not enough. Read on to get up to speed on this emerging field.
Video by: Steve
Using examples as well as descriptions, step through each of the common simple join types, explaining differences in syntax, differences in expected outputs and showing how the queries run along with the actual outputs based upon a simple set of dem…
This is a high-level webinar that covers the history of enterprise open source database use. It addresses both the advantages companies see in using open source database technologies, as well as the fears and reservations they might have. In this…
Suggested Courses

571 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question