Skip to Main Content
  • Questions
  • Determining the row locked ina table

Breadcrumb

Question and Answer

Tom Kyte

Thanks for the question, Navdeep.

Asked: September 29, 2000 - 10:38 am UTC

Last updated: June 22, 2008 - 9:44 pm UTC

Version: Oracle8 Enterprise Edition Release 8.0.5.1.0

Viewed 1000+ times

You Asked

Tom,

I want to be able to figure out as to which rows in a table are locked. I can get to know which table is locked in a database using a join between dba_objects and v$locked_object. But How do i get to the row level in that table.

Thanks
Navdeep


and Tom said...

We do not keep a list of row locks anywhere.

We store the lock as an attribute of the data itself. The only way to find out if row "X" is locked is to attempt to lock it yourself (via select ... from t where ... FOR UPDATE NOWAIT).

Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

am i wrong

A reader, June 22, 2008 - 3:34 pm UTC

does this query gets row level locking please correct me if i am wrong?

SELECT owner obj_owner,
object_name obj_name,
object_type obj_type,
dbms_rowid.rowid_create(1, row_wait_obj#, ROW_WAIT_FILE#, ROW_WAIT_BLOCK#,ROW_WAIT_ROW#) obj_rowid,
a.username db_user, a.SID SID, a.TYPE lock_type,
a.row_wait_file#, a.row_wait_block#, a.row_wait_row#
FROM dba_OBJECTS,
(SELECT /*+ no_merge(a) no_merge(b) */
a.username, a.SID, a.row_wait_obj#, a.ROW_WAIT_FILE#,
a.ROW_WAIT_BLOCK#, a.ROW_WAIT_ROW#, b.TYPE
FROM sys.V_$SESSION a, sys.V_$LOCK b
WHERE a.username IS NOT NULL
AND a.row_wait_obj# <> -1
AND a.SID = b.SID
AND b.TYPE IN ('TX','TM')
) a
WHERE object_id = a.row_wait_obj#;

Tom Kyte
June 22, 2008 - 9:44 pm UTC

if you are asking "does this query, which uses hints in a nonsense fashion, show me all of the rows a session has locked"

http://docs.oracle.com/docs/cd/B19306_01/server.102/b14200/sql_elements006.htm#SQLRF50507

your use of the no_merge hint is useless. But it looks cool. Hints are that way - makes it look cool.

the answer is "no" - there is no way to see that.


why don't you try this:

ask a question

rather than post an answer to an unknown question that may or may not even answer that question.