我有以下触发器:
CREATE OR REPLACE TRIGGER SOL.AFTERIUDLIQUIDATIONSDETAILS
BEFORE INSERT OR DELETE
ON SOL.LIQUIDATIONSDETAILS
FOR EACH ROW
BEGIN
IF INSERTING
THEN
UPDATE APPOINTSOFCAS
SET INLD = INLD + 1
WHERE CUSTOMERID = :NEW.CUSTOMERID
AND ID = :NEW.APPOINTOFCAID
AND KINDCONTROLID = :NEW.KINDCONTROLID;
END IF;
IF DELETING
THEN
UPDATE APPOINTSOFCAS
SET INLD = INLD - 1
WHERE CUSTOMERID = :NEW.CUSTOMERID
AND ID = :NEW.APPOINTOFCAID
AND KINDCONTROLID = :NEW.KINDCONTROLID;
END IF;
END;
案例if
插入工作正常,但案例ID不删除。有什么想法吗?
答案 0 :(得分:1)
当您删除the field values in the NEW
pseudorecord are all null时,在使用这些字段进行查询时,没有任何内容匹配。您需要改为引用OLD
:
IF DELETING
THEN
UPDATE APPOINTSOFCAS
SET INLD = INLD - 1
WHERE CUSTOMERID = :OLD.CUSTOMERID
AND ID = :OLD.APPOINTOFCAID
AND KINDCONTROLID = :OLD.KINDCONTROLID;
END IF;
如果同时插入或删除两个会话,则可能会出现并发问题;在APPOINTSOFCAS
提交后,你得到的最终值可能不是你所期望的。