I have a table called TBLAPPLICATION which holds data specifying an individual’s ID number and a JobID of the job they have applied for. Each ID number can have an unlimited number of applications, providing the JobID is different every time, thus having no duplicate applications.
create or replace
TRIGGER trg_duplicateapplication BEFORE INSERT ON tblapplication FOR EACH ROW
BEGIN
IF :NEW.studentrecordnumber_fk_nn = :OLD.studentrecordnumber_fk_nn THEN
IF :NEW.jobid_fk_nn = :OLD.jobid_fk_nn
THEN RAISE_APPLICATION_ERROR( -20003, 'Error: duplicate application. You have already applied for this position.');
END IF;
END IF;
END;
So the above code doesn’t work, and I wish it would. Could anyone please highlight my mistake? 🙂
As it stands, your trigger is comparing the inserted values (
:NEW.studentrecordnumber_fk_nnetc) with a non-existent:OLD(:OLDhas no meaning to anINSERTtrigger—it’s fields are alwaysnull).That aside, this should almost certainly be accomplished by DRI instead of a trigger at all— how about a unique index on
(studentrecordnumber_fk_nn, jobid_fk_nn)?