CREATE OR REPLACE TRIGGER ATUALIZA_CLIENFILIAL
AFTER INSERT
ON FILIAL FOR EACH ROW

DECLARE
   V_CDCLIENTE VARCHAR2(21);
BEGIN
   BEGIN
      SELECT CDCLIENTE
        INTO V_CDCLIENTE
        FROM GERPARAMGERAL;
   EXCEPTION
      WHEN NO_DATA_FOUND THEN BEGIN
         V_CDCLIENTE := NULL;
      END;
   END;

   IF V_CDCLIENTE IS NOT NULL THEN
      INSERT INTO CLIENFILIAL
         (CDFILIAL, CDCLIENTE, IDCLIENPRIN, IDPERMVENDAFOS, IDBAIXACONSCLIF)
      VALUES
         (:NEW.CDFILIAL, V_CDCLIENTE, 'S', 'S', 'S');
   END IF;
END;
/
