create or replace 
TRIGGER LOG_OPORTUNIDADE BEFORE UPDATE ON CRM_OPORTUNI 
FOR EACH ROW 
DECLARE
   V_NRSEQLOGOPORT NUMBER;
BEGIN
   IF UPDATING THEN
      IF (NVL(:OLD.NRPARCOPORT,0) <> NVL(:NEW.NRPARCOPORT,0))   THEN
         NOVO_CODIGO_NT('CRM_LOGOPORT',V_NRSEQLOGOPORT,10);
         INSERT INTO CRM_LOGOPORT (NRSEQLOGOPORT, NRSEQOPORT, DTLOGOPORT, NMFIELDLOGOPORT,VRFIELDNOVO,VRFIELDANT, DTINCLUSAO, CDOPERINCLUSAO, NRORGINCLUSAO)
                       VALUES (V_NRSEQLOGOPORT, :OLD.NRSEQOPORT, SYSDATE, 'NRPARCOPORT', :NEW.NRPARCOPORT, :OLD.NRPARCOPORT, SYSDATE, :NEW.CDOPERULTATU, :NEW.NRORGULTATU);
      END IF;
      IF (NVL(:OLD.NRPARCRESP ,0) <> NVL(:NEW.NRPARCRESP ,0))    THEN
          NOVO_CODIGO_NT('CRM_LOGOPORT',V_NRSEQLOGOPORT,10);
         INSERT INTO CRM_LOGOPORT (NRSEQLOGOPORT, NRSEQOPORT, DTLOGOPORT, NMFIELDLOGOPORT,VRFIELDNOVO,VRFIELDANT, DTINCLUSAO, CDOPERINCLUSAO, NRORGINCLUSAO)
                       VALUES (V_NRSEQLOGOPORT, :OLD.NRSEQOPORT, SYSDATE, 'NRPARCRESP', :NEW.NRPARCRESP, :OLD.NRPARCRESP, SYSDATE, :NEW.CDOPERULTATU, :NEW.NRORGULTATU);
      END IF;
      IF (NVL(TO_CHAR(:OLD.DTPREVFECHA),0) <> NVL(TO_CHAR(:NEW.DTPREVFECHA),0))   THEN
         NOVO_CODIGO_NT('CRM_LOGOPORT',V_NRSEQLOGOPORT,10);
         INSERT INTO CRM_LOGOPORT (NRSEQLOGOPORT, NRSEQOPORT, DTLOGOPORT, NMFIELDLOGOPORT,VRFIELDNOVO,VRFIELDANT, DTINCLUSAO, CDOPERINCLUSAO, NRORGINCLUSAO)
                       VALUES (V_NRSEQLOGOPORT, :OLD.NRSEQOPORT, SYSDATE, 'DTPREVFECHA', TO_CHAR(:NEW.DTPREVFECHA,'DD/MM/YYYY'), TO_CHAR(:OLD.DTPREVFECHA,'DD/MM/YYYY'), SYSDATE, :NEW.CDOPERULTATU, :NEW.NRORGULTATU);
      END IF;      
      IF (NVL(:OLD.IDPARTPEPELINE,0) <> NVL(:NEW.IDPARTPEPELINE,0))   THEN
         NOVO_CODIGO_NT('CRM_LOGOPORT',V_NRSEQLOGOPORT,10);
         INSERT INTO CRM_LOGOPORT (NRSEQLOGOPORT, NRSEQOPORT, DTLOGOPORT, NMFIELDLOGOPORT,VRFIELDNOVO,VRFIELDANT, DTINCLUSAO, CDOPERINCLUSAO, NRORGINCLUSAO)
                       VALUES (V_NRSEQLOGOPORT, :OLD.NRSEQOPORT, SYSDATE, 'IDPARTPEPELINE', :NEW.IDPARTPEPELINE, :OLD.IDPARTPEPELINE, SYSDATE, :NEW.CDOPERULTATU, :NEW.NRORGULTATU);
      END IF;
      IF (NVL(:OLD.NRSEQRESULEVOL,0) <> NVL(:NEW.NRSEQRESULEVOL,0))   THEN
         NOVO_CODIGO_NT('CRM_LOGOPORT',V_NRSEQLOGOPORT,10);
         INSERT INTO CRM_LOGOPORT (NRSEQLOGOPORT, NRSEQOPORT, DTLOGOPORT, NMFIELDLOGOPORT,VRFIELDNOVO,VRFIELDANT, DTINCLUSAO, CDOPERINCLUSAO, NRORGINCLUSAO)
                       VALUES (V_NRSEQLOGOPORT, :OLD.NRSEQOPORT, SYSDATE, 'NRSEQRESULEVOL', :NEW.NRSEQRESULEVOL, :OLD.NRSEQRESULEVOL, SYSDATE, :NEW.CDOPERULTATU, :NEW.NRORGULTATU);
      END IF;
      IF (NVL(:OLD.VROPORT,0) <> NVL(:NEW.VROPORT,0))   THEN
         NOVO_CODIGO_NT('CRM_LOGOPORT',V_NRSEQLOGOPORT,10);
         INSERT INTO CRM_LOGOPORT (NRSEQLOGOPORT, NRSEQOPORT, DTLOGOPORT, NMFIELDLOGOPORT,VRFIELDNOVO,VRFIELDANT, DTINCLUSAO, CDOPERINCLUSAO, NRORGINCLUSAO)
                       VALUES (V_NRSEQLOGOPORT, :OLD.NRSEQOPORT, SYSDATE, 'VROPORT', :NEW.VROPORT, :OLD.VROPORT, SYSDATE, :NEW.CDOPERULTATU, :NEW.NRORGULTATU);
      END IF;
      IF (NVL(:OLD.IDTPOPORT,0) <> NVL(:NEW.IDTPOPORT,0))   THEN
         NOVO_CODIGO_NT('CRM_LOGOPORT',V_NRSEQLOGOPORT,10);
         INSERT INTO CRM_LOGOPORT (NRSEQLOGOPORT, NRSEQOPORT, DTLOGOPORT, NMFIELDLOGOPORT,VRFIELDNOVO,VRFIELDANT, DTINCLUSAO, CDOPERINCLUSAO, NRORGINCLUSAO)
                       VALUES (V_NRSEQLOGOPORT, :OLD.NRSEQOPORT, SYSDATE, 'IDTPOPORT', :NEW.IDTPOPORT, :OLD.IDTPOPORT, SYSDATE, :NEW.CDOPERULTATU, :NEW.NRORGULTATU);
      END IF;
      IF (NVL(:OLD.NRSEQFASENEGO,0) <> NVL(:NEW.NRSEQFASENEGO,0))   THEN
         NOVO_CODIGO_NT('CRM_LOGOPORT',V_NRSEQLOGOPORT,10);
         INSERT INTO CRM_LOGOPORT (NRSEQLOGOPORT, NRSEQOPORT, DTLOGOPORT, NMFIELDLOGOPORT,VRFIELDNOVO,VRFIELDANT, DTINCLUSAO, CDOPERINCLUSAO, NRORGINCLUSAO)
                       VALUES (V_NRSEQLOGOPORT, :OLD.NRSEQOPORT, SYSDATE, 'NRSEQFASENEGO', :NEW.NRSEQFASENEGO, :OLD.NRSEQFASENEGO, SYSDATE, :NEW.CDOPERULTATU, :NEW.NRORGULTATU);
      END IF;
   END IF;

END;
/