Hi im working on a trigger that will not allow inserts/updates when the newly inserted data (address, listnumber, date, price) has a similar tuple.
Condition – a listing cannot be listed twice on the same day
table
123, jun 19 1992
123, jun 20 1990
insert: 123, Jun 20 1990 – wouldnt work already in table
The only problem with my code is that i cant get it work when my list table has no data to begin with
create or replace TRIGGER same_prop_listed BEFORE INSERT OR UPDATE ON HasListing
FOR each ROW
DECLARE
c_date VARCHAR2(20);
BEGIN
SELECT LISTING_DATE
INTO c_date
FROM HasListing
WHERE PROP_ADDRESS = :NEW.prop_address;
IF (c_date = :NEW.listing_date) THEN
RAISE_APPLICATION_ERROR(-20001,'Cannot list same property twice in one day!');
END IF;
EXCEPTION
WHEN NO_DATA_FOUND THEN
RAISE_APPLICATION_ERROR(-20003,'No DATA');
END;
This is in oracle.
So my errors are on – IF (c_date = :NEW.listing_date) because c_date is null
Why don’t you just put a multiple column unique constraint ?
?