WITH lock_holders AS
(
SELECT w.session_id w_sess_id, h.session_id h_sess_id,
w.lock_type w_lock_type, h.mode_held h_mode_held,
w.mode_requested w_mode_requested, w.lock_id1 w_lock_id1,
w.lock_id2 w_lock_id2
FROM (SELECT session_id, lock_type, mode_requested, lock_id1,
lock_id2
FROM dba_lock
WHERE mode_requested != 'None') w,
(SELECT session_id, mode_held,lock_type,lock_id1,lock_id2
FROM dba_lock
WHERE blocking_others = 'Blocking'
AND mode_held != 'None'
AND mode_held != 'Null') h
WHERE w.lock_type = h.lock_type
AND w.lock_id1 = h.lock_id1
AND w.lock_id2 = h.lock_id2)
SELECT LPAD(' ', 3 *(LEVEL - 1)) || w_sess_id waiting_session,
w_lock_type, w_mode_requested, h_mode_held, w_lock_id1, w_lock_id2
FROM (SELECT *
FROM lock_holders
UNION ALL
(SELECT h_sess_id, NULL, 'None', NULL, NULL, NULL, NULL
FROM lock_holders
MINUS
SELECT w_sess_id, NULL, 'None', NULL, NULL, NULL, NULL
FROM lock_holders))
CONNECT BY PRIOR w_sess_id = h_sess_id
START WITH h_sess_id IS NULL
|