SQL> create table tab1
2 (id number,
3 info varchar2(10),
4 constraint tab1_pk primary key (id)
5 using index
6* (create index idx_tab1_pk on tab1(id)))
SQL> insert into tab1
2 select rownum, 'aaaaaa'||rownum
3 from dual
4 connect by rownum <=5;
5 rows created.
SQL> select id
2 from tab1
3 where id = (select min(id) from tab1)
4 for update;
V$lock
ADDR KADDR SID TY ID1 ID2 LMODE REQUEST CTIME BLOCK
-------- -------- ---------- -- ---------- ---------- ---------- ---------- ---------- ----------
385247F0 3852481C 71 AE 99 0 4 0 533 0
3852494C 38524978 41 AE 99 0 4 0 291 0
385249C0 385249EC 41 TX 65561 166 0 6 144 0
00DE464C 00DE467C 41 TM 12467 0 3 0 144 0
00DE464C 00DE467C 71 TM 12467 0 3 0 219 0
37FD9C20 37FD9C60 71 TX 65561 166 6 0 219 1
Los tipos de bloqueos AE, solo aparecen en las versiones 11gR1 y 11gR2. Pero se aprecia claramente que la sesión 71 obtuvo el bloqueo exclusivo sobre la fila, y la sesión 41 está a pidiendo un bloqueo exclusivo sobre la misma.
SQL> delete tab1 where id=1;
1 row deleted.
SQL> COMMIT;
Commit complete.
SQL> select id
2 from tab1
3 where id = (select min(id) from tab1)
4 for update;
ID
----------
2
--------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
--------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 3 (100)| |
| 1 | FOR UPDATE | | | | | |
|* 2 | INDEX RANGE SCAN | IDX_TAB1_PK | 1 | 13 | 1 (0)| 00:00:01 |
| 3 | SORT AGGREGATE | | 1 | 13 | | |
| 4 | INDEX FULL SCAN (MIN/MAX)| IDX_TAB1_PK | 4 | 52 | 2 (0)| 00:00:01 |
--------------------------------------------------------------------------------------------
----------------------------------------------------------------------------------------------
| Id | Operation | Name | Rows | Bytes | Cost (%CPU)| Time |
----------------------------------------------------------------------------------------------
| 0 | SELECT STATEMENT | | | | 3 (100)| |
| 1 | FOR UPDATE | | | | | |
| 2 | BUFFER SORT | | | | | |
|* 3 | INDEX RANGE SCAN | IDX_TAB1_PK | 1 | 13 | 1 (0)| 00:00:01 |
| 4 | SORT AGGREGATE | | 1 | 13 | | |
| 5 | INDEX FULL SCAN (MIN/MAX)| IDX_TAB1_PK | 4 | 52 | 2 (0)| 00:00:01 |
----------------------------------------------------------------------------------------------
delete tab2 where id = (select min(id) from tab2);
update tab1 set id=id+10
where id = (select min(id) from tab1);