I'm trying to find if there's more than 1 president in my database with a trigger and if yes, raise an error, I'm using hr, the table employees and I have to use the job_id to find it. Here's what my code looks like. Thanks!
CREATE OR REPLACE TRIGGER check_pres
BEFORE INSERT OR DELETE OR UPDATE ON employees
FOR EACH ROW
BEGIN
IF ((employees.job_id = 'AD_PRES') > 1)
THEN RAISE_APPLICATION_ERROR(-12345, 'More than one President in database.');
END IF;
END;
You should use
Statement Level Triggerinstead ofRow Level Triggerby removingFOR EACH ROWexpressionotherwise you'd get mutating error while getting the count value. Btw, the first argument value for
RAISE_APPLICATION_ERRORshould be between-20999and-20000