Oracle SQL触发器在实现时会发生变化

Oracle SQL触发器在实现时会发生变化,sql,oracle,triggers,mutating-table,Sql,Oracle,Triggers,Mutating Table,此触发器在执行插入或更新操作时遇到问题。但是,触发器的创建没有错误。目的是检查发票总额是否大于付款总额+信用总额。任何帮助都将不胜感激: Create or Replace Trigger invoices_before_update_payment Before Insert or Update On invoices For Each Row Declare InvTotal Number; t_payment Number; t_credit Number; Begin select in

此触发器在执行插入或更新操作时遇到问题。但是,触发器的创建没有错误。目的是检查发票总额是否大于付款总额+信用总额。任何帮助都将不胜感激:

Create or Replace Trigger invoices_before_update_payment
Before Insert or Update On invoices
For Each Row
Declare
InvTotal Number;
t_payment Number;
t_credit Number;
Begin
select invoice_total, payment_total, credit_total
Into
InvTotal, t_payment, t_credit
From invoices
Where invoice_id = :New.invoice_id;
DBMS_OUTPUT.PUT_LINE(InvTotal);
If (InvTotal) < (t_payment + t_credit)
Then
Raise_application_error(-20005, 'Invoice total is larger than the credit total and payment total');
End if;
End;
/
在更新付款之前创建或替换触发发票
在发票上插入或更新之前
每行
声明
总人数;
付款编号;
t_信用编号;
开始
选择发票总额、付款总额、信用总额
进入
投资总额、t_付款、t_信用
从发票
其中invoice\u id=:New.invoice\u id;
DBMS_OUTPUT.PUT_行(InvTotal);
如果(投资总额)<(t_付款+t_信用)
然后
提出申请错误(-20005,“发票总额大于信用总额和付款总额”);
如果结束;
结束;
/

您不能从表中选择触发的触发器,否则会出现此错误

为什么不直接在触发器中使用:新值

BEGIN
IF :new.invoice_total > :new.payment_total + :new.credit_total THEN
我根据错误消息语义反转了关系运算符