Being still a newbie in PL/SQL, I’ve been copying and pasting around the following trigger:
CREATE OR REPLACE TRIGGER FOO_TRG1
BEFORE INSERT
ON FOO
REFERENCING NEW AS NEW OLD AS OLD
FOR EACH ROW
BEGIN
IF :NEW.FOO_ID IS NULL THEN
SELECT FOO_SEQ1.NEXTVAL INTO :NEW.FOO_ID FROM DUAL;
END IF;
EXCEPTION
WHEN OTHERS THEN RAISE;
END FOO_TRG1;
/
ALTER TRIGGER FOO_TRG1 ENABLE;
I suspect that the included exception handling code does nothing at all and could simply get removed, since I’ll get an error message anyway if something goes wrong. Am I right?
(I guess such code is the result of further editing prior code.)
yes, that exception does nothing but raise the same error out. also it serves to mask the real line number of the error. i’d remove that if I were you.
eg:
vs:
the line number in the first one is pointing to the raise instead of the real line number. it can make tracking down errors harder.