1120 11g select for update skip locked

简介: [20171120]11g select for update skip locked.txt --//11G在select for update遇到阻塞时可以通过skipped locked跳过阻塞的记录,测试看看: 1.

[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条记录.

目录
相关文章
|
6月前
【开发专题_02】Executing an update/delete query
【开发专题_02】Executing an update/delete query
67 0
|
关系型数据库 MySQL
深入理解SELECT ... LOCK IN SHARE MODE和SELECT ... FOR UPDATE
深入理解SELECT ... LOCK IN SHARE MODE和SELECT ... FOR UPDATE
|
11月前
|
SQL 关系型数据库 MySQL
INSERT ... ON DUPLICATE KEY UPDATE Statement
INSERT ... ON DUPLICATE KEY UPDATE Statement
78 0
|
SQL 关系型数据库 MySQL
mysql Error Code: 1175. You are using safe update mode and you tried to update a table without ....
mysql Error Code: 1175. You are using safe update mode and you tried to update a table without ....
218 0
mysql Error Code: 1175. You are using safe update mode and you tried to update a table without ....
|
关系型数据库 MySQL 数据库
MySQL问题解决:Cannot delete or update a parent row: a foreign key constraint fails
MySQL问题解决:Cannot delete or update a parent row: a foreign key constraint fails
1322 0
|
关系型数据库 MySQL
Mysql - 删除表时出现: Cannot delete or update a parent row: a foreign key constraint fails
Mysql - 删除表时出现: Cannot delete or update a parent row: a foreign key constraint fails
249 0
Unsafe query: ‘Update‘ statement without ‘where‘ updates all table rows at once
Unsafe query: ‘Update‘ statement without ‘where‘ updates all table rows at once
688 0
|
关系型数据库 数据库 PostgreSQL
【DB吐槽大会】第70期 - PG 不支持update | delete skip locked, nowait语法
大家好,这里是DB吐槽大会,第70期 - PG 不支持update | delete skip locked, nowait语法
|
SQL 关系型数据库
get_locked_objects_rpt.sql
在metalink上看到一个脚本(get_locked_objects_rpt.sql),非常不错,如下所示 /*----------------------------------------------------------------------------+ | MODULE: get_locked_objects_rpt.
893 0