db2插入触发器new无效

时间:2019-04-09 11:10:23

标签: database plsql triggers db2 database-trigger

我已经定义了此触发器:

--#SET TERMINATOR @
CREATE TRIGGER actualizarSaldoIngreso
BEFORE INSERT ON Ingreso
FOR EACH ROW MODE DB2SQL
BEGIN
    UPDATE Cuenta SET Saldo = Saldo + NEW.Cantidad WHERE IBAN = NEW.Cuenta_IBAN;
END@
--#SET TERMINATOR ;

但是db2返回此错误。有什么解决办法吗?

"NEW.CANTIDAD" is not valid in the context where it is used.

1 个答案:

答案 0 :(得分:3)

--#SET TERMINATOR @
CREATE TRIGGER actualizarSaldoIngreso
BEFORE INSERT ON Ingreso
REFERENCING NEW as N
FOR EACH ROW MODE DB2SQL
BEGIN
    UPDATE Cuenta SET Saldo = Saldo + N.Cantidad WHERE IBAN = N.Cuenta_IBAN;
END@
--#SET TERMINATOR ;