create or replace TRIGGER TG_ATUALIZA_ENDEPROSPECT
AFTER UPDATE
ON ENDERECOPARC
REFERENCING NEW AS NEW
FOR EACH ROW
BEGIN
    IF :NEW.CDTIPOENDERECO = 'PRINCIPAL'
        THEN UPDATE ENDEPROSPECT SET DTULTATU = SYSDATE,
                                     CDPAIS = :NEW.CDPAIS,
                                     SGESTADO = :NEW.SGESTADO,
                                     CDMUNICIPIO = :NEW.CDMUNICIPIO,
                                     CDBAIRRO = :NEW.CDBAIRRO,
                                     DSENDEPROS = :NEW.DSENDERECO,
                                     NMBAIRPROS = :NEW.NMBAIRROENDERECO,
                                     NRCEPPROS = :NEW.NRCEPENDERECO,
                                     NRIMOVELENDERECO = :NEW.NRIMOVELENDERECO
        WHERE IDTPENDEPROS = 'P'
          AND NRORG = :NEW.NRORG
          AND CDPROSPECT = (SELECT CDPROSPECT FROM PROSPECT
                             WHERE NRPARCNEGOCIO = :NEW.NRPARCNEGOCIO
                               AND NRORG = :NEW.NRORG
                               AND ROWNUM = 1);
    END IF;
END;