今天在写一个触发器时遇到一个死锁问题,但不知道问题出在哪儿,这个触发器主要是用处是在T_BS_ORDERDETAIL表做增删改操作时给主表T_BS_ORDERINFO重新合计重量体积及数量CREATE OR REPLACE TRIGGER TRIGGER_ORDERDETAIL
AFTER DELETE OR INSERT OR UPDATE ON T_BS_ORDERDETAIL FOR EACH ROWDECLARE
PRAGMA AUTONOMOUS_TRANSACTION;BEGIN
UPDATE T_BS_ORDERINFO A SET A.N_ZL =
(SELECT SUM(B.N_ZL) FROM T_BS_ORDERDETAIL B WHERE B.I_ID_ORDER = :NEW.I_ID_ORDER),
A.N_TJ =
(SELECT SUM(B.N_TJ) FROM T_BS_ORDERDETAIL B WHERE B.I_ID_ORDER = :NEW.I_ID_ORDER),
A.I_ALLCOUNT =
(SELECT SUM(B.I_COUNT) FROM T_BS_ORDERDETAIL B WHERE B.I_ID_ORDER = :NEW.I_ID_ORDER) WHERE A.ID = :NEW.I_ID_ORDER; COMMIT;END;新增时没报错,但修改时就报以下错误
1 回答
长风秋雁
TA贡献1757条经验 获得超7个赞
CREATE OR REPLACE TRIGGER TRIGGER_ORDERDETAIL AFTER DELETE OR INSERT OR UPDATE ON T_BS_ORDERDETAIL FOR EACH ROWBEGIN IF INSERTING THEN UPDATE T_BS_ORDERINFO A SET A.N_ZL=A.N_ZL+:NEW.N_ZL, A.N_TJ=A.N_TJ+:NEW.N_TJ, A.I_ALLCOUNT=A.I_ALLCOUNT+:NEW.I_COUNT WHERE A.ID=:NEW.I_ID_ORDER; END IF; IF UPDATING THEN UPDATE T_BS_ORDERINFO A SET A.N_ZL=A.N_ZL-:OLD.N_ZL+:NEW.N_ZL, A.N_TJ=A.N_TJ-:OLD.N_TJ+:NEW.N_TJ, A.I_ALLCOUNT=A.I_ALLCOUNT-:OLD.I_COUNT+:NEW.I_COUNT WHERE A.ID=:NEW.I_ID_ORDER; END IF; IF DELETING THEN UPDATE T_BS_ORDERINFO A SET A.N_ZL=A.N_ZL-:OLD.N_ZL, A.N_TJ=A.N_TJ-:OLD.N_TJ, A.I_ALLCOUNT=A.I_ALLCOUNT-:OLD.I_COUNT WHERE A.ID=:OLD.I_ID_ORDER; END IF;END;
- 1 回答
- 0 关注
- 1144 浏览
添加回答
举报
0/150
提交
取消