我有这个触发器,它接近我想要完成的任务,但在尝试之后我仍然无法完成。
我做了什么
CREATE or REPLACE TRIGGER TR_UPD_TEST_TABLE_B
AFTER INSERT ON TEST_TABLE_A
FOR EACH ROW
DECLARE
BEGIN
FOR VAL IN (SELECT * FROM TEST_TABLE_B A WHERE A.ID = :NEW.ID) LOOP
IF :NEW.QTY_RECEIVED > VAL.QTY_PRE_RECEIVED THEN
UPDATE TEST_TABLE_B A SET A.QTY_RECEIVED = 888 WHERE A.ID = :NEW.ID;
ELSE
UPDATE TEST_TABLE_B A SET A.QTY_RECEIVED = 111 WHERE A.ID = :NEW.ID;
END IF;
END LOOP;
END;
问题
通过使用IF :NEW.QTY_RECEIVED > VAL.QTY_PRE_RECEIVED
,我想将 :NEW.QTY_RECEIVED 与每条记录进行比较,但似乎它总计了所有记录的数量。因此语句总是跳到 ,ELSE
因为总量大于:NEW.QTY_RECEIVED
。