CREATE OR REPLACE
TRIGGER ATUALIZA_IDPACH_SOLISERV 
BEFORE INSERT OR UPDATE ON SOLISERV FOR EACH ROW
DECLARE
   V_IDLIBPATCHSL ASSUNTO.IDLIBPATCHSL%TYPE;
BEGIN
   IF :NEW.IDBAIXAPATCH IS NULL THEN
      SELECT NVL(MAX(IDLIBPATCHSL),'N')
        INTO V_IDLIBPATCHSL
        FROM ASSUNTO
        WHERE CDASSUNTO = :NEW.CDASSUNTO;
      :NEW.IDBAIXAPATCH := V_IDLIBPATCHSL;
   END IF;
END;
/