I want to create an update trigger for a table called payment that will update the cost column with the difference between get_out and get_in multiplied price value from another entity
I don't have much experience with creating triggers but so far this is what I've got
CREATE OR REPLACE TRIGGER o1 BEFORE UPDATE OF get_out ON payment
FOR EACH ROW
BEGIN
UPDATE payment
SET payment.cost = ROUND (24 * (to_date(payment.get_out)-to_date(payment.get_in)),0) *
(SELECT price FROM payment,book,place
WHERE book.ID_place = place.ID_place
AND payment.ID_payment = book.ID_payment
AND payment.ID_payment = :NEW.payment.ID_payment
)
;
END;
/
I get this error when creating the trigger:
Trigger created with compilation errors.
LINE/COL ERROR
---------- -----------------------------------------------------------
7/43 PLS-00049: bad bind variable 'NEW.PAYMENT'
Any suggestion? Thanks
you're trying to
updateyour tablepaymentin yourupdate trigger. Just assign the returning value of join to the column:new.cost.prefer using the
JOIN ONsyntax instead of deprecated former syntax, and take the tablebookas the first in tables order syntax.there's a careless attempt on
:new.payment.ID_payment, which should be:new.ID_paymentinstead.By the way, if the columns
get_outandget_inare of typedate, and just holddate valuewithoutdate and time info(24.12.2017, instead of24.12.2017 08:00), then no need to cast using to_date in your substraction.