visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Databases :: Oracle :: oracle table lock mechanism with SELECT ... FOR UPDATE


By: Josdeveld Belgium  Date: 20/07/2005 11:09:53  English  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 English  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 English  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

EContact
browser fav
page generated in 291.483880 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page