[20171120]11g select for update skip locked.txt
--//11G在select for update遇到阻塞时可以通过skipped locked跳过阻塞的记录,测试看看:
1.环境:
SCOTT@book> @ &r/ver1
PORT_STRING VERSION BANNER
------------------------------ -------------- --------------------------------------------------------------------------------
x86_64/Linux 2.4.xx 11.2.0.4.0 Oracle Database 11g Enterprise Edition Release 11.2.0.4.0 - 64bit Production
SCOTT@book> create table empx as select * from emp ;
Table created.
2.测试:
--//session 1:
SCOTT@book> select count(*) from empx ;
COUNT(*)
------------
14
SCOTT@book> update empx set sal=sal+100 where deptno=10;
3 rows updated.
--//sesson 2:
SCOTT@book> select * from empx for update ;
--//挂起!!
--//session 1:
SCOTT@book> @ &r/viewlock
SID SERIAL# USERNAME OSUSER MACHINE MODULE LOCK_TYPE MODE_HELD MODE_REQUE LOCK_ID1 LOCK_ID2 OWNER OBJECT_TYP OBJECT_NAME BLOCK LOCKWAIT
------ ------------ ---------- ---------- ---------- ------------ --------------- ---------- ---------- ---------- ---------- ------ ---------- -------------------- ----- --------------------
80 15 SCOTT oracle xxxxxxx SQL*Plus TM DML(TM) Row-X (SX) None 90707 0 SCOTT TABLE EMPX No 0000000084C350B8
80 15 SCOTT oracle xxxxxxx SQL*Plus TX Transaction Exclusive None 589847 2894 No 0000000084C350B8
80 15 SCOTT oracle xxxxxxx SQL*Plus TX Transaction None Exclusive 655366 22646 No 0000000084C350B8
274 9 SCOTT oracle xxxxxxx SQL*Plus TX Transaction Exclusive None 655366 22646 Yes
274 9 SCOTT oracle xxxxxxx SQL*Plus TM DML(TM) Row-X (SX) None 90707 0 SCOTT TABLE EMPX No
SCOTT@book> select * from empx for update skip locked;
EMPNO ENAME JOB MGR HIREDATE SAL COMM DEPTNO
---------- ---------- --------- ---------- ------------------- ---------- ---------- ----------
7369 SMITH CLERK 7902 1980-12-17 00:00:00 800 20
7499 ALLEN SALESMAN 7698 1981-02-20 00:00:00 1600 300 30
7521 WARD SALESMAN 7698 1981-02-22 00:00:00 1250 500 30
7566 JONES MANAGER 7839 1981-04-02 00:00:00 2975 20
7654 MARTIN SALESMAN 7698 1981-09-28 00:00:00 1250 1400 30
7698 BLAKE MANAGER 7839 1981-05-01 00:00:00 2850 30
7788 SCOTT ANALYST 7566 1987-04-19 00:00:00 3000 20
7844 TURNER SALESMAN 7698 1981-09-08 00:00:00 1500 0 30
7876 ADAMS CLERK 7788 1987-05-23 00:00:00 1100 20
7900 JAMES CLERK 7698 1981-12-03 00:00:00 950 30
7902 FORD ANALYST 7566 1981-12-03 00:00:00 3000 20
11 rows selected.
--//可以显示没有上lock的11条记录.