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

x
?
Solved

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

Posted on 2005-04-15
7
Medium Priority
?
9,720 Views
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



0
Comment
Question by:vvs
5 Comments
 
LVL 22

Accepted Solution

by:
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:
http://download-west.oracle.com/docs/cd/B10501_01/appdev.920/a96590/adg08sql.htm#8123
0
 
LVL 8

Expert Comment

by:Pierrick LOUBIER
ID: 13789267
You can use SELECT FOR UPDATE
0
 
LVL 11

Expert Comment

by:sujit_kumar
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.
0
 
LVL 25

Expert Comment

by:jrb1
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.
0
 

Author Comment

by:vvs
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
0

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