CREATE OR REPLACE TRIGGER TGR_AGENSAL_HRINIUTILSAL
BEFORE INSERT OR UPDATE ON AGENDASALAO FOR EACH ROW
DECLARE V_HORAEVENTO VARCHAR2(5);
BEGIN
    IF (INSTR(:NEW.HRINIUTILSALAO, ':') > 0) THEN
        SELECT TO_CHAR(DTEVENTO, 'HH24:MI') DTEVENTO
          INTO V_HORAEVENTO
          FROM ORCAEVENTO
         WHERE CDFILIAL     = :NEW.CDFILIAL
           AND NRORCAEVENTO = :NEW.NRORCAEVENTO
           AND NRSEQORCAEVE = :NEW.NRSEQORCAEVE;
           :NEW.HRINIUTILSALAO := REPLACE(V_HORAEVENTO, ':', '');
    END IF;
END;
/
