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

당신은 다른 사람이 오류가 트리거가 발사되는 테이블에서 선택할 수 없습니다.

트리거에 새 값을 사용하지 않는 이유는 무엇입니까?

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

오류 메시지 의미론을 기반으로 관계 연산자를 바꿨습니다.