I'm trying to create a trigger to prevent inserts/updates on a table where the booking date is the same as the current date.
CREATE OR REPLACE TRIGGER driver_bookings BEFORE INSERT OR UPDATE ON Bookings
FOR EACH ROW WHEN (new.DriverID = old.DriverID)
IF TO_DATE(:new.StartDate, 'DD.MM.YYYY') = TO_DATE(sysdate,'DD.MM.YYYY');
raise_application_error(-20014, 'Booking cannot be made at this time.');
The table has (BookingID, BookingDate, StartDate).
To check that the trigger fires i am inserting this value into the table:
INSERT INTO Bookings VALUES (6,TO_DATE('9.11.2012','DD.MM.YYYY'), TO_DATE('09.11.2012/20:12','DD.MM.YYYY/HH24:MI');
For some reason the trigger allows the insert when it shouldnt and i have no idea whats wrong.
The trigger would surely not fire for inserts because there is no old value at that point. The logic should work just fine for updates though. Just to clarify the trigger is only executing when the DRIVERID in the table is the same as the proposed DRIVERID.