2013-09-26 28 views
0

在执行插入或更新操作时遇到此触发器的问题。虽然触发器得到创建没有错误。目标是检查invoice_total是否大于payment_total + credit_total的总数。任何帮助将不胜感激:Oracle SQL触发器在实现时发生变异

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; 
/

回答

1

你不能从表中选择一个触发器正在触发,否则你会得到这个错误。

为什么不简单在触发器中使用:new values?

BEGIN 
IF :new.invoice_total > :new.payment_total + :new.credit_total THEN 

我根据错误消息语义颠倒了关系运算符。