Databases :: Oracle :: oracle table lock mechanism with SELECT ... FOR UPDATE |
|||
| By: Josdeveld |
Date: 20/07/2005 11:09:53 |
Points: 20 | Status: Answered Quality : Excellent |
|
Hello, I'm doing a SELECT * INTO ord FROM TBLPNT_ORDER o WHERE o.pnt_orderid = x_orderid FOR UPDATE; I want to avoid the table lock on other rows. How do I do that ? |
|||
| By: VGR | Date: 20/07/2005 11:16:17 | Type : Answer |
|
| In fact, you may be slighty confused (no wonder ;-) at Oracle's locking mechanisms. You are getting a table lock only without a WHERE clause. In that case, if someone else already has a table lock, you get the error ORA-00054: resource busy and acquire with NOWAIT specified. In your case, you just attempt to create a ROW lock. For row-level locks, each subsequent lock will wait for it's turn at the row, as you didn't specify NOWAIT. If you had specified NOWAIT, the subsequent accesses to the same rows would produce the ORA-54 error. |
|||
| By: VGR | Date: 20/07/2005 11:23:41 | Type : Comment |
|
| Please not also that even if the SELECT ... FOR UPDATE returned no rows, Oracle locks the table in Row share mode -- this prevents another session from locking that table in exclusive mode but nothing else. There are no TX (transaction) locks -- hence no rows are locked in that table. I will post the following in "Knowledge Base" to get the locks of the current session. This may help you. select (select object_name from user_objects where object_id = lock_id1) obj_name, lock_type, mode_held from dba_locks where session_id = (select sid from v$mystat where rownum=1) |
|||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








