当前位置: 代码迷 >> DB2 >> db2存储过程执行表和存储过程就死锁怎么处理
  详细解决方案

db2存储过程执行表和存储过程就死锁怎么处理

热度:5568   发布时间:2013-02-26 00:00:00.0
db2存储过程执行表和存储过程就死锁怎么办
大家,我的存储过程一执行就死锁了,麻烦大家看看存储过程怎么了,代码有点长,麻烦耐心看完。曾经有次能执行,可能出现问题的地方是
SQL code
SET ROWCOUNT = (SELECT COUNT(*) FROM USERID.T_SBMX_LNODE WHERE PARENT_ID = xl_ID AND SJLX_ID = 1041);
以及游标。

SQL code
CREATE PROCEDURE USERID.PROC_SD_TOPO3 (  IN XL_ID BIGINT )   LANGUAGE SQL  NOT DETERMINISTIC  CALLED ON NULL INPUT  MODIFIES SQL DATA  INHERIT SPECIAL REGISTERS  P1: BEGIN ATOMIC  DECLARE TEMP_PARENT_ID BIGINT;DECLARE TEMP_SJLX_ID BIGINT;          --临时设计设备类型ID DECLARE TEMP_QLNODE_ID BIGINT;        --临时支线连接的起始杆塔ID DECLARE TEMP_HLNODE_ID BIGINT;         --临时支线连接的终止杆塔ID DECLARE TEMP_QBDZ_ID BIGINT;        --临时主线连接的起始变电站ID DECLARE TEMP_HBDZ_ID BIGINT;           --临时主线连接的终止变电站ID DECLARE IS_QLNODE BIGINT;        --支线是否存在起始杆塔(0:不存在;1:存在)DECLARE IS_HLNODE BIGINT;        --支线是否存在终止杆塔(0:不存在;1:存在)DECLARE IS_QBDZ BIGINT;            --主线是否存在起始变电站(0:不存在;1:存在)DECLARE IS_HBDZ BIGINT;            --主线是否存在终止变电站(0:不存在;1:存在)DECLARE IS_Q BIGINT;             --是否存在起始设备DECLARE TOPO_ORDER_NUM INTEGER DEFAULT 0;    --排序序号DECLARE TOPO_FNODE_DEV_ID BIGINT;    --起始杆塔ID DECLARE TOPO_TNODE_DEV_ID BIGINT;    --终止杆塔ID DECLARE ROWCOUNT INTEGER;--定义游标,查询线路下的所有杆塔(按运行位置编号升序)DECLARE cur1 CURSOR FOR SELECT A.ID AS F_GT, (SELECT B.ID FROM USERID.T_SBMX_LNODE B  WHERE B.LNODEBH > A.LNODEBH AND B.PARENT_ID = 330328 AND B.SJLX_ID = 1041 ORDER BY B.LNODEBH ASC  FETCH FIRST 1 ROWS ONLY) AS T_GTFROM USERID.T_SBMX_LNODE AWHERE A.PARENT_ID = 330328AND A.SJLX_ID = 1041ORDER BY A.LNODEBH ASCFOR FETCH ONLY;SET ROWCOUNT = (SELECT COUNT(*) FROM USERID.T_SBMX_LNODE WHERE PARENT_ID = xl_ID AND SJLX_ID = 1041);  --判断输入的线路是主线还是支线SELECT PARENT_ID, QLNODE_ID, HLNODE_ID INTO TEMP_PARENT_ID, TEMP_QLNODE_ID, TEMP_HLNODE_ID FROM USERID.T_SBMX_LNODE WHERE ID = xl_ID;SELECT SJLX_ID INTO TEMP_SJLX_ID FROM USERID.T_SBMX_LNODE WHERE ID = TEMP_PARENT_ID;IF (TEMP_SJLX_ID = 2447)       --输入的线路是支线时  THEN   SET TEMP_SJLX_ID = 0;   SELECT SJLX_ID    INTO TEMP_SJLX_ID    FROM USERID.T_SBMX_LNODE    WHERE ID = TEMP_QLNODE_ID;    IF (TEMP_SJLX_ID = 1041)         THEN       SET IS_QLNODE = 1;   END IF;      SET TEMP_SJLX_ID = 0;   SELECT SJLX_ID    INTO TEMP_SJLX_ID    FROM USERID.T_SBMX_LNODE    WHERE ID = TEMP_HLNODE_ID;    IF (TEMP_SJLX_ID = 1041)         THEN       SET IS_HLNODE = 1;   END IF;                             ELSE                         --输入的线路是主线时 IF (TEMP_PARENT_ID <> 0) THEN  --查询起始变电站ID和终止变电站ID   SELECT B.SCOLD1S5, B.SCOLD1S6  INTO TEMP_QBDZ_ID, TEMP_HBDZ_ID  FROM USERID.T_SBMX_LNODE A LEFT JOIN USERID.T_SBMX_SB_QT B ON A.SB_ID = B.ID   WHERE A.ID = TEMP_PARENT_ID;            SET TEMP_SJLX_ID = 0;   SELECT SJLX_ID    INTO TEMP_SJLX_ID    FROM USERID.T_SBMX_LNODE    WHERE ID = TEMP_QBDZ_ID;    IF (TEMP_SJLX_ID = 2269)         THEN       SET IS_QBDZ = 1;   END IF;          SET TEMP_SJLX_ID = 0;   SELECT SJLX_ID    INTO TEMP_SJLX_ID    FROM USERID.T_SBMX_LNODE    WHERE ID = TEMP_HBDZ_ID;    IF (TEMP_SJLX_ID = 2269)         THEN       SET IS_HBDZ = 1;   END IF;  END IF;                                                END IF;IF (ROWCOUNT > 1) THEN DELETE FROM USER_SCDBZS.T_POWER_TOPO3 WHERE PAPERID = xl_ID;END IF;--处理线路下的所有杆塔OPEN cur1;cursorLoop1:LOOPFETCH cur1 INTO TOPO_FNODE_DEV_ID, TOPO_TNODE_DEV_ID;      SET TOPO_ORDER_NUM = TOPO_ORDER_NUM + 1;IF (IS_QLNODE = 1)      --支线连接的起始杆塔存在时   THEN   SET IS_QLNODE = 0;   INSERT INTO USER_SCDBZS.T_POWER_TOPO3(PAPERID, ORDER_NUM, LINKLINE_LOGIC_ID, FNODE_DEV_ID, TNODE_DEV_ID)   VALUES(xl_ID, TOPO_ORDER_NUM, xl_ID, TEMP_QLNODE_ID, TOPO_FNODE_DEV_ID);     SET IS_Q = 1;END IF;IF (IS_QBDZ = 1)      --主线连接的起始变电站存在时   THEN   SET IS_QBDZ = 0;   INSERT INTO USER_SCDBZS.T_POWER_TOPO3(PAPERID, ORDER_NUM, LINKLINE_LOGIC_ID, FNODE_DEV_ID, TNODE_DEV_ID)   VALUES(xl_ID, TOPO_ORDER_NUM, xl_ID, TEMP_QBDZ_ID, TOPO_FNODE_DEV_ID);     SET IS_Q = 1;END IF;IF (IS_Q = 1) THEN SET IS_Q = 0; SET TOPO_ORDER_NUM = TOPO_ORDER_NUM + 1;END IF;IF (TOPO_FNODE_DEV_ID IS NOT NULL AND TOPO_TNODE_DEV_ID IS NOT NULL) THEN--向拓扑表添加线路上的杆塔数据INSERT INTO USER_SCDBZS.T_POWER_TOPO3(PAPERID, ORDER_NUM, LINKLINE_LOGIC_ID, FNODE_DEV_ID, TNODE_DEV_ID)VALUES(xl_ID, TOPO_ORDER_NUM, xl_ID, TOPO_FNODE_DEV_ID, TOPO_TNODE_DEV_ID);  END IF; END LOOP;CLOSE cur1;IF (IS_HLNODE = 1)   --支线连接的终止杆塔存在时   THEN   SET IS_HLNODE = 0;   SET TOPO_ORDER_NUM = TOPO_ORDER_NUM + 1;   INSERT INTO USER_SCDBZS.T_POWER_TOPO3(PAPERID, ORDER_NUM, LINKLINE_LOGIC_ID, FNODE_DEV_ID, TNODE_DEV_ID)   VALUES(xl_ID, TOPO_ORDER_NUM, xl_ID, TOPO_TNODE_DEV_ID, TEMP_HLNODE_ID);  END IF;IF (IS_HBDZ = 1)   --主线连接的终止变电站存在时   THEN   SET IS_HBDZ = 0;   SET TOPO_ORDER_NUM = TOPO_ORDER_NUM + 1;   INSERT INTO USER_SCDBZS.T_POWER_TOPO3(PAPERID, ORDER_NUM, LINKLINE_LOGIC_ID, FNODE_DEV_ID, TNODE_DEV_ID)   VALUES(xl_ID, TOPO_ORDER_NUM, xl_ID, TOPO_TNODE_DEV_ID, TEMP_HBDZ_ID);  END IF;END P1;
  相关解决方案