Trigger how to fix these errors Code Answer

Hello Developer, Hope you guys are doing great. Today at Tutorial Guruji Official website, we are sharing the answer of Trigger how to fix these errors without wasting too much if your time.

The question is published on by Tutorial Guruji team.

I am trying to make a trigger for every day a movie gets returned late 2$ gets added to the unpaid balance. The return and due date are in the transaction table, and the unpaid balance is in the members table. Here is what I have so far, and the errors I am getting any help or suggestions would be great I am really struggling with this one.

Create or Replace Trigger Late_Rule
BEFORE INSERT ON Transaction
For each Row
DECLARE

Fee Number;

BEGIN

Select Date_Due, Date_Returned  
From Transaction;

If new.Date_Returned > new.Date_Due
THEN 
Fee := (new.Date_Returned - new.Date_Due) * 2;


END IF;

Update Member
    Set Unpaid_Bal = Unpaid_Bal + Fee;
end;
/
show error;

7/1 PLS-00428: an INTO clause is expected in this SELECT statement
10/1 PL/SQL: Statement ignored
10/4 PLS-00201: identifier ‘NEW.DATE_RETURNED’ must be declared

Answer

You must use : before new. Also i think you don’t need select sentence:

Create or Replace Trigger Late_Rule
BEFORE INSERT ON Transaction
For each Row
DECLARE

Fee Number;

BEGIN


If :new.Date_Returned > :new.Date_Due
THEN 
Fee := (:new.Date_Returned - :new.Date_Due) * 2;


END IF;

Update Member
    Set Unpaid_Bal = Unpaid_Bal + Fee;
end;

Let me know if you get any error.

We are here to answer your question about Trigger how to fix these errors - If you find the proper solution, please don't forgot to share this with your team members.

Related Posts

Tutorial Guruji