CREATE OR REPLACE TRIGGER TRGCARGA_CLIENTE
AFTER INSERT OR UPDATE OR DELETE
ON CLIENTE FOR EACH ROW
BEGIN

   IF INSERTING THEN
      INSERT INTO USR_CARGA_CLIENTE (ID_CLIENTE, ID_EMPRESA, ID_MATRICULA, NM_CLIENTE, TP_PESSOA, TX_CGC_CPF, TX_INSCRICAO,
                                     DT_NASC, TX_ENDERECO, TX_BAIRRO, TX_CIDADE, TX_UF, TX_CEP, TP_ATUALIZACAO, OP_IMP)
      VALUES (0, 0, 0, :NEW.NMRAZSOCCLIE, :NEW.IDTPIJURCLIE, SUBSTR(:NEW.CDCLIENTE, 2, 30), :NEW.NRINSESTCLIE,
              :NEW.DTNASCCLIE, '', '', '', '', '', 'I', 'N');

   ELSIF UPDATING THEN
      UPDATE USR_CARGA_CLIENTE
      SET NM_CLIENTE     = :NEW.NMRAZSOCCLIE,
          TP_PESSOA      = :NEW.IDTPIJURCLIE,
          TX_INSCRICAO   = :NEW.NRINSESTCLIE,
          DT_NASC        = :NEW.DTNASCCLIE,
          TP_ATUALIZACAO = 'A'
      WHERE TX_CGC_CPF = SUBSTR(:OLD.CDCLIENTE, 2, 30);

   ELSIF DELETING THEN
      UPDATE USR_CARGA_CLIENTE
      SET TP_ATUALIZACAO = 'E'
      WHERE TX_CGC_CPF = SUBSTR(:OLD.CDCLIENTE, 2, 30);

   END IF;
END;
/


-- VERSAO --
BEGIN ATUVEROBJ('TRGCARGA_CLIENTE','4.11.033'); END;
/

