create or replace trigger trig_einbau before INSERT or UPDATE ON Einbau for each row declare Baugrp Bauteil.Baugruppe%TYPE; BEGIN if inserting then select Baugruppe INTO Baugrp from Bauteil where Bauteil.BtNr = :new.BtNr; if Baugrp = NULL then return; END IF; Select sq_einbau.nextval into :new.EbNr from dual; END IF; if updating then :new.EbNr := :old.EbNr; END IF; END;