抓取锁的sql语句-第二次修改

CREATE OR REPLACE PROCEDURE SOLVE_LOCK

AS

V_SQL VARCHAR2(3000);  --定义 v_sql 接受抓取锁的sql语句
 CUR_LOCK SYS_REFCURSOR; --定义游标变量,循环执行抓取锁的sql语句

TYPE TP_LOCK IS RECORD(   --定义 record类型的 变量
 V_SID NUMBER,
 V_TYPE VARCHAR2(10),
 V_ID1 NUMBER,
 V_ID2 NUMBER,
 V_LMODE VARCHAR2(200),
 V_REQUEST  VARCHAR2(200),
 V_LOCK_TIME NUMBER,
 V_BLOCK  NUMBER );
 
-- V_TYPE VARCHAR2(30),

RECORDS_LOCK TP_LOCK;

BEGIN
   V_SQL:=‘SELECT SID,TYPE,ID1,ID2,
   DECODE(LMODE,0, ‘‘NONE‘‘,1,‘‘NULL‘‘, 2, ‘‘ROW SHARE‘‘ ,3, ‘‘ROW EXCLUSIVE‘‘ ,4, ‘‘SHARE‘‘ ,5, ‘‘SHARE ROW EXCLUSIVE‘‘ ,6  ,‘‘EXCLUSIVE‘‘ ,‘‘HAHA‘‘) LOCK_TYPE,
   DECODE(REQUEST,0, ‘‘NONE‘‘,1,‘‘NULL‘‘, 2, ‘‘ROW SHARE‘‘ ,3, ‘‘ROW EXCLUSIVE‘‘ ,4, ‘‘SHARE‘‘ ,5, ‘‘SHARE ROW EXCLUSIVE‘‘ ,6  ,‘‘EXCLUSIVE‘‘ ,‘‘HAHA‘‘) LOCK_REQUEST,
   CTIME,BLOCK FROM V$LOCK WHERE SID IN (133,68)‘ ;
 
 -- V_SQL:=‘SELECT SID,TYPE,ID1,ID2, DECORD(LMODE,0, NONE,1,‘NULL‘ 2, ‘ROW SHARE‘ ,3, ‘ROW EXCLUSIVE‘ 4, ‘SHARE‘ 5, ‘SHARE ROW EXCLUSIVE‘ 6  ,‘EXCLUSIVE‘ ,‘HAHA‘) LOCK_TYPE,REQUEST,CTIME,BLOCK FROM V$LOCK WHERE SID IN (133,9)‘ ;

OPEN CUR_LOCK FOR V_SQL;
 LOOP  
   FETCH CUR_LOCK INTO RECORDS_LOCK;
       
   EXIT WHEN CUR_LOCK%NOTFOUND;

IF RECORDS_LOCK.V_REQUEST <> ‘NONE‘  THEN    --抓取发出请求锁的会话
  DBMS_OUTPUT.PUT_LINE(‘SID: ‘||RECORDS_LOCK.V_SID||‘ is request a lock ,lock_mode  is ‘||RECORDS_LOCK.V_REQUEST||‘ and being locked ‘|| RECORDS_LOCK.V_LOCK_TIME);
END IF;

IF RECORDS_LOCK.V_BLOCK  <>0 THEN   --抓取发生锁阻塞的会话
  DBMS_OUTPUT.put_line(‘SID: ‘||RECORDS_LOCK.V_SID||‘ is make a lock , lock_mode is ‘||RECORDS_LOCK.V_LMODE);
  END IF;
   
  -- DBMS_OUTPUT.put_line(RECORDS_LOCK.V_SID);

END LOOP;
   CLOSE CUR_LOCK;

END SOLVE_LOCK;

时间: 2024-12-17 20:49:14

抓取锁的sql语句-第二次修改的相关文章

抓取锁的sql语句-第六次修改

增加异常处理 CREATE OR REPLACE PROCEDURE SOLVE_LOCK AS V_SQL VARCHAR2(3000); --定义 v_sql 接受抓取锁的sql语句V_SQL02 VARCHAR2(3000); KILL_SID NUMBER;KILL_SERIAL NUMBER; CUR_LOCK SYS_REFCURSOR; --定义游标变量,循环执行抓取锁的sql语句CUR_LOCK02 SYS_REFCURSOR; TYPE TP_LOCK IS RECORD( -

抓取锁的sql语句-第五次修改

CREATE OR REPLACE PROCEDURE SOLVE_LOCK AS V_SQL VARCHAR2(3000); --定义 v_sql 接受抓取锁的sql语句V_SQL02 VARCHAR2(3000);V_SQL03 VARCHAR2(3000); KILL_SID NUMBER;KILL_SERIAL NUMBER; CUR_LOCK SYS_REFCURSOR; --定义游标变量,循环执行抓取锁的sql语句CUR_LOCK02 SYS_REFCURSOR; TYPE TP_L

抓取锁的sql语句-第四次修改

--完成情况   变量V_BLOCKING_SID 用来动态抓取 产生锁的会话id,输出参数没有任何问题,但是执行报错  标识符无效! CREATE OR REPLACE PROCEDURE SOLVE_LOCK123 AS V_SQL VARCHAR2(3000); --定义 v_sql 接受抓取锁的sql语句V_SQL02 VARCHAR2(3000);V_SQL03 VARCHAR2(3000); KILL_SID NUMBER;KILL_SERIAL NUMBER; CUR_LOCK S

抓取锁的sql语句-第三次修改

CREATE OR REPLACE PROCEDURE SOLVE_LOCK AS V_SQL VARCHAR2(3000); --定义 v_sql 接受抓取锁的sql语句CUR_LOCK SYS_REFCURSOR; --定义游标变量,循环执行抓取锁的sql语句 TYPE TP_LOCK IS RECORD( --定义 record类型的 变量V_SID NUMBER,V_TYPE VARCHAR2(10),V_ID1 NUMBER,V_ID2 NUMBER,V_LMODE VARCHAR2(

用SQL语句添加删除修改字段

1.增加字段     alter table docdsp     add dspcodechar(200)2.删除字段     ALTER TABLE table_NAME DROP COLUMNcolumn_NAME3.修改字段类型     ALTER TABLE table_name     ALTER COLUMNcolumn_name new_data_type4.sp_rename 改名     EXEC sp_rename '[dbo].[Table_1].[filedName1]

用SQL语句添加删除修改字段、一些表与字段的基本操作、数据库备份等

用SQL语句添加删除修改字段 1.增加字段 alter table docdsp add dspcode char(200) 2.删除字段 ALTER TABLE table_NAME DROP COLUMN column_NAME 3.修改字段类型 ALTER TABLE table_name ALTER COLUMN column_name new_data_type 4.sp_rename 改名 更改当前数据库中用户创建对象(如表.列或用户定义数据类型)的名称. 语法 sp_rename

sql server抓取表结构的语句

sql server 2008抓取方法: --------------------------------------- SELECT 表名 = Case When A.colorder=1 Then D.name Else '' End, 表说明 = Case When A.colorder=1 Then isnull(F.value,'') Else '' End, 字段序号 = A.colorder, 字段名 = A.name, 字段说明 = isnull(G.[value],''), 标

用SQL语句添加删除修改字段_常用SQL

1.增加字段     alter table docdsp     add dspcodechar(200)2.删除字段     ALTER TABLE table_NAME DROP COLUMNcolumn_NAME3.修改字段类型     ALTER TABLE table_name     ALTER COLUMNcolumn_name new_data_type4.sp_rename 改名     EXEC sp_rename '[dbo].[Table_1].[filedName1]

Oracle抓取表结构的语句

oracle --------------------------------------- SELECT case when t.COLUMN_ID=1 then t.table_name end table_name, case when t.COLUMN_ID=1 then t2.comments end table_comments, t.COLUMN_ID,t.colUMN_NAME,t1.comments,case when t3.COLUMN_NAME is not null th