2013-09-26 63 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 

我根據錯誤消息語義顛倒了關係運算符。