CREATE OR REPLACE TRIGGER LOG_QPR_AUDITORIA 
AFTER DELETE OR INSERT OR UPDATE
ON AUDITORIA FOR EACH ROW
DECLARE
  V_DSREMOTEADDR VARCHAR2(15); 
  V_DSREMOTEHOST VARCHAR2(15);
  V_DSSERVERRDM  VARCHAR2(20);
  V_DSSERVMETHOD VARCHAR2(30);
  V_DSREMOTEOPER VARCHAR2(12);
  V_GRAV_DESC    VARCHAR2(700);
  V_DESC         VARCHAR2(3000);
  V_LENGTH       FLOAT(10);
  V_CONT_LENGTH FLOAT(10);
  V_ITPESQ       VARCHAR2(80);
  V_NMOPERADOR   VARCHAR2(40);
  V_NRINCREST    VARCHAR2(40);
  V_IDTIPOOPER   VARCHAR2(1);
  V_CDFILLOGOPER VARCHAR2(4);

BEGIN
/* IDTIPOOPER - '1' - Inclusão, '2' - Alteração, '3' - Exclusão*/

   V_GRAV_DESC    := '';
   V_LENGTH       := '';  
   V_CONT_LENGTH  := 1;
   V_DESC       := '';
   V_ITPESQ     := '';
   V_NMOPERADOR := '';
   V_NRINCREST  := '';
   V_IDTIPOOPER := '';
   V_CDFILLOGOPER := '';
   
   NMUSUARIO(V_NMOPERADOR);
   WEBTUNNING(V_DSREMOTEADDR,
              V_DSREMOTEHOST,
              V_DSSERVERRDM,
              V_DSSERVMETHOD,
              V_DSREMOTEOPER);

   IF INSERTING THEN

      IF :NEW.CDFILIAL IS NOT NULL THEN
         V_DESC := V_DESC || 'Filial= ' || NVL(:NEW.CDFILIAL,'') || ' ' ;
      END IF;

      IF :NEW.NRAUDITORIA IS NOT NULL THEN
         V_DESC := V_DESC || 'NrAudit.= ' || NVL(:NEW.NRAUDITORIA,'') || ' ' ;
      END IF;

      IF :NEW.CDOPEINCAUDI IS NOT NULL THEN
         V_DESC := V_DESC || 'CDOPEINCAUDI= ' || NVL(:NEW.CDOPEINCAUDI,'') || ' ';
      END IF;

      IF :NEW.DTINCLAUDIT IS NOT NULL THEN
         V_DESC := V_DESC || 'DTINCLAUDIT= ' || NVL(:NEW.DTINCLAUDIT,'') || ' ';
      END IF;

      IF :NEW.IDTPAUDITADO IS NOT NULL THEN
         V_DESC := V_DESC || 'IDTPAUDITADO= ' || NVL(:NEW.IDTPAUDITADO,'') || ' ';
      END IF;

      IF :NEW.CDCLIENTE IS NOT NULL THEN
         V_DESC := V_DESC || 'CDCLIENTE= ' || NVL(:NEW.CDCLIENTE,'') || ' ';
      END IF;

      IF :NEW.CDFORNECED IS NOT NULL THEN
         V_DESC := V_DESC || 'CDFORNECED= ' || NVL(:NEW.CDFORNECED,'') || ' ';
      END IF;

      IF :NEW.CDTIPAUDIT IS NOT NULL THEN
         V_DESC := V_DESC || 'CDTIPAUDIT= ' || NVL(:NEW.CDTIPAUDIT,'') || ' ';
      END IF;

      IF :NEW.CDCRITAVAFIN IS NOT NULL THEN
         V_DESC := V_DESC || 'CDCRITAVAFIN= ' || NVL(:NEW.CDCRITAVAFIN,'') || ' ';
      END IF;

      IF :NEW.DTINIPREVAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'DTINIPREVAUD= ' || NVL(TO_CHAR(:NEW.DTINIPREVAUD, 'DD/MM/YYYY'),'') || ' ';
      END IF;

      IF :NEW.DTFINPREVAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'DTFINPREVAUD= ' || NVL(TO_CHAR(:NEW.DTFINPREVAUD, 'DD/MM/YYYY'),'') || ' ';
      END IF;

      IF :NEW.DTINIREALAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'DTINIREALAUD= ' || NVL(TO_CHAR(:NEW.DTINIREALAUD, 'DD/MM/YYYY'),'') || ' ';
      END IF;

      IF :NEW.DTFINREALAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'DTFINREALAUD= ' || NVL(TO_CHAR(:NEW.DTFINREALAUD, 'DD/MM/YYYY'),'') || ' ';
      END IF;

      IF :NEW.QTTEMPVALAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'QTTEMPVALAUD= ' || TO_CHAR(:NEW.QTTEMPVALAUD) || ' ';
      END IF;

      IF :NEW.IDUNTEMPVAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'IDUNTEMPVAUD= ' || NVL(:NEW.IDUNTEMPVAUD,'') || ' ';
      END IF;

      IF :NEW.DTVALIDAUDIT IS NOT NULL THEN
         V_DESC := V_DESC || 'DTVALIDAUDIT= ' || NVL(TO_CHAR(:NEW.DTVALIDAUDIT, 'DD/MM/YYYY'),'') || ' ';
      END IF;

      IF :NEW.NMPESCONTAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'NMPESCONTAUD= ' || :NEW.NMPESCONTAUD || ' ';
      END IF;

      IF :NEW.CDTIPORESU IS NOT NULL THEN
         V_DESC := V_DESC || 'CDTIPORESU=  ' || :NEW.CDTIPORESU || ' ';
      END IF;

      IF :NEW.DSREFEAUDIT IS NOT NULL THEN
         V_DESC := V_DESC || 'DSREFEAUDIT= ' || :NEW.DSREFEAUDIT || ' ';
      END IF;

      IF :NEW.DSAUDITORIA IS NOT NULL THEN
         V_DESC := V_DESC || 'DSAUDITORIA= ' || :NEW.DSAUDITORIA || ' ';
      END IF;

      IF :NEW.IDORIGAUDIT IS NOT NULL THEN
         V_DESC := V_DESC || 'IDORIGAUDIT= ' || :NEW.IDORIGAUDIT || ' ';
      END IF;

      IF :NEW.CDSETSOLIAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'CDSETSOLIAUD= ' || :NEW.CDSETSOLIAUD || ' ';
      END IF;

      IF :NEW.CDSETRECEAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'CDSETRECEAUD= ' || :NEW.CDSETRECEAUD || ' ';
      END IF;

      IF :NEW.CDSETEXECAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'CDSETEXECAUD= ' || :NEW.CDSETEXECAUD || ' ' ;
      END IF;

      IF :NEW.NRLOTEESTQ IS NOT NULL THEN
         V_DESC := V_DESC || 'NRLOTEESTQ= ' || :NEW.NRLOTEESTQ || ' ' ;
      END IF;

      IF :NEW.NRSUBLOTE IS NOT NULL THEN
         V_DESC := V_DESC || 'NRSUBLOTE= ' || :NEW.NRSUBLOTE || ' ' ;
      END IF;

      IF :NEW.NMOPEINCAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'NMOPEINCAUD= ' || :NEW.NMOPEINCAUD || ' ' ;
      END IF;

      IF :NEW.CDPRODUTO IS NOT NULL THEN
         V_DESC := V_DESC || 'CDPRODUTO= ' || :NEW.CDPRODUTO || ' ' ;
      END IF;

      IF :NEW.NRORDPROD IS NOT NULL THEN
         V_DESC := V_DESC || 'NRORDPROD= ' || NVL(:NEW.NRORDPROD,'') || ' ' ;
      END IF;

      IF :NEW.NRSUBORDPROD IS NOT NULL THEN
         V_DESC := V_DESC || 'NRSUBORDPROD= ' || NVL(:NEW.NRSUBORDPROD,'') || ' ' ;
      END IF;

      IF :NEW.CDETAPAPROD IS NOT NULL THEN
         V_DESC := V_DESC || 'CDETAPAPROD= ' || NVL(:NEW.CDETAPAPROD,'') || ' ';
      END IF;

      IF :NEW.CDEQUIPPRO IS NOT NULL THEN
         V_DESC := V_DESC || 'CDEQUIPPRO= ' || NVL(:NEW.CDEQUIPPRO,'') || ' ';
      END IF;

      IF :NEW.IDSTATUSAUDI IS NOT NULL THEN
         V_DESC := V_DESC || 'IDSTATUSAUDI= ' || NVL(:NEW.IDSTATUSAUDI,'') || ' ';
      END IF;

      IF :NEW.VRAPRPRODAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'VRAPRPRODAUD= ' || NVL(:NEW.VRAPRPRODAUD,'') || ' ';
      END IF;

      IF :NEW.NRPRIORAUDI IS NOT NULL THEN
         V_DESC := V_DESC || 'NRPRIORAUDI= ' || NVL(:NEW.NRPRIORAUDI,'') || ' ';
      END IF;

      IF :NEW.NRLANCTONF IS NOT NULL THEN
         V_DESC := V_DESC || 'NRLANCTONF= ' || NVL(:NEW.NRLANCTONF,'') || ' ';
      END IF;

      IF :NEW.NRSEQITPROD IS NOT NULL THEN
         V_DESC := V_DESC || 'NRSEQITPROD= ' || NVL(:NEW.NRSEQITPROD,'') || ' ';
      END IF;

      IF :NEW.DTAMOSAUDI IS NOT NULL THEN
         V_DESC := V_DESC || 'DTAMOSAUDI= ' || NVL(TO_CHAR(:NEW.DTAMOSAUDI, 'DD/MM/YYYY'),'') || ' ';
      END IF;

      IF :NEW.DTVALANA IS NOT NULL THEN
         V_DESC := V_DESC || 'DTVALANA= ' || NVL(TO_CHAR(:NEW.DTVALANA, 'DD/MM/YYYY'),'') || ' ';
      END IF;

      IF :NEW.QTHRAUDIT IS NOT NULL THEN
         V_DESC := V_DESC || 'QTHRAUDIT= ' || TO_CHAR(:NEW.QTHRAUDIT) || ' ';
      END IF;

      IF :NEW.IDLIBERAUDIT IS NOT NULL THEN
         V_DESC := V_DESC || 'IDLIBERAUDIT= ' || NVL(:NEW.IDLIBERAUDIT,'') || ' ';
      END IF;

      IF :NEW.CDPRODANTE IS NOT NULL THEN
         V_DESC := V_DESC || 'CDPRODANTE= ' || NVL(:NEW.CDPRODANTE,'') || ' ';
      END IF;

      IF :NEW.CDPROSPECT IS NOT NULL THEN
         V_DESC := V_DESC || 'CDPROSPECT= ' || :NEW.CDPROSPECT || ' ';
      END IF;

      IF :NEW.NRORDIMPAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'NRORDIMPAUD=  ' || :NEW.NRORDIMPAUD || ' ';
      END IF;

      IF :NEW.QTAMOSAUDI IS NOT NULL THEN
         V_DESC := V_DESC || 'QTAMOSAUDI= ' || :NEW.QTAMOSAUDI || ' ';
      END IF;

      IF :NEW.CDFILIALNF IS NOT NULL THEN
         V_DESC := V_DESC || 'CDFILIALNF= ' || :NEW.CDFILIALNF || ' ';
      END IF;

      IF :NEW.CDFILIORCA IS NOT NULL THEN
         V_DESC := V_DESC || 'CDFILIORCA= ' || :NEW.CDFILIORCA || ' ';
      END IF;

      IF :NEW.NRORCAEVENTO IS NOT NULL THEN
         V_DESC := V_DESC || 'NRORCAEVENTO= ' || :NEW.NRORCAEVENTO || ' ';
      END IF;

      IF :NEW.NRSEQORCAEVE IS NOT NULL THEN
         V_DESC := V_DESC || 'NRSEQORCAEVE= ' || :NEW.NRSEQORCAEVE || ' ';
      END IF;

      IF :NEW.CDOPERRESPALT IS NOT NULL THEN
         V_DESC := V_DESC || 'Ope. Aut.= ' || :NEW.CDOPERRESPALT || ' ' ;
      END IF;

      IF :NEW.CDJUSTALTERA IS NOT NULL THEN
         V_DESC := V_DESC || 'Just.:= ' || :NEW.CDJUSTALTERA || ' ' ;
      END IF;

      IF :NEW.IDAUDIPIL IS NOT NULL THEN
         V_DESC := V_DESC || 'IDAUDIPIL= ' || :NEW.IDAUDIPIL || ' ' ;
      END IF;

      IF :NEW.IDTIPOANA IS NOT NULL THEN
         V_DESC := V_DESC || 'IDTIPOANA= ' || :NEW.IDTIPOANA || ' ' ;
      END IF;

      IF :NEW.QTMOVIMENTADA IS NOT NULL THEN
         V_DESC := V_DESC || 'QTMOVIMENTADA= ' || :NEW.QTMOVIMENTADA || ' ' ;
      END IF;

      IF :NEW.IDGERADOJOB IS NOT NULL THEN
         V_DESC := V_DESC || 'IDGERADOJOB= ' || :NEW.IDGERADOJOB || ' ' ;
      END IF;

      IF :NEW.IDGERADOREANA IS NOT NULL THEN
         V_DESC := V_DESC || 'IDGERADOREANA= ' || :NEW.IDGERADOREANA || ' ' ;
      END IF;

      IF :NEW.IDENVIAVISO IS NOT NULL THEN
         V_DESC := V_DESC || 'IDENVIAVISO= ' || :NEW.IDENVIAVISO || ' ' ;
      END IF;

      IF :NEW.IDCOMPATIBILIDADE IS NOT NULL THEN
         V_DESC := V_DESC || 'IDCOMPATIBILIDADE= ' || :NEW.IDCOMPATIBILIDADE || ' ' ;
      END IF;

      IF :NEW.CDOPERLIBAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'CDOPERLIBAUD= ' || :NEW.CDOPERLIBAUD || ' ' ;
      END IF;

      IF :NEW.QTESTOQATUAL IS NOT NULL THEN
         V_DESC := V_DESC || 'QTESTOQATUAL= ' || :NEW.QTESTOQATUAL || ' ' ;
      END IF;

      IF :NEW.QTESTQAPROVA IS NOT NULL THEN
         V_DESC := V_DESC || 'QTESTQAPROVA= ' || :NEW.QTESTQAPROVA || ' ' ;
      END IF;

      IF :NEW.QTESTQREPROVA IS NOT NULL THEN
         V_DESC := V_DESC || 'QTESTQREPROVA= ' || :NEW.QTESTQREPROVA || ' ' ;
      END IF;

      IF :NEW.NRSUBLOTEPARC IS NOT NULL THEN
         V_DESC := V_DESC || 'NRSUBLOTEPARC= ' || :NEW.NRSUBLOTEPARC || ' ' ;
      END IF;

      V_ITPESQ := :NEW.CDFILIAL || :NEW.NRAUDITORIA;

      V_IDTIPOOPER := '1';
      V_CDFILLOGOPER := :NEW.CDFILIAL;

   END IF;

      IF UPDATING THEN

         IF (:NEW.CDFILIAL <> :OLD.CDFILIAL) THEN
            V_DESC := V_DESC || 'Filial= ' || NVL(:NEW.CDFILIAL,'') || ' ' ;
         END IF;

         IF (:NEW.NRAUDITORIA <> :OLD.NRAUDITORIA) THEN
            V_DESC := V_DESC || 'NrAudit.= ' || NVL(:NEW.NRAUDITORIA,'') || ' ' ;
         END IF;

         IF (:NEW.CDOPEINCAUDI <> :OLD.CDOPEINCAUDI) THEN
            V_DESC := V_DESC || 'CDOPEINCAUDI= ' || NVL(:NEW.CDOPEINCAUDI,'') || ' ';
         END IF;

         IF (:NEW.DTINCLAUDIT <> :OLD.DTINCLAUDIT) THEN
            V_DESC := V_DESC || 'DTINCLAUDIT= ' || NVL(:NEW.DTINCLAUDIT,'') || ' ';
         END IF;

         IF (:NEW.IDTPAUDITADO <> :OLD.IDTPAUDITADO) THEN
            V_DESC := V_DESC || 'IDTPAUDITADO= ' || NVL(:NEW.IDTPAUDITADO,'') || ' ';
         END IF;

         IF (:NEW.CDCLIENTE <> :OLD.CDCLIENTE) THEN
            V_DESC := V_DESC || 'CDCLIENTE= ' || NVL(:NEW.CDCLIENTE,'') || ' ';
         END IF;

         IF (:NEW.CDFORNECED <> :OLD.CDFORNECED) THEN
            V_DESC := V_DESC || 'CDFORNECED= ' || NVL(:NEW.CDFORNECED,'') || ' ';
         END IF;

         IF (:NEW.CDTIPAUDIT <> :OLD.CDTIPAUDIT) THEN
            V_DESC := V_DESC || 'CDTIPAUDIT= ' || NVL(:NEW.CDTIPAUDIT,'') || ' ';
         END IF;

         IF (:NEW.CDCRITAVAFIN <> :OLD.CDCRITAVAFIN) THEN
            V_DESC := V_DESC || 'CDCRITAVAFIN= ' || NVL(:NEW.CDCRITAVAFIN,'') || ' ';
         END IF;

         IF (:NEW.DTINIPREVAUD <> :OLD.DTINIPREVAUD) THEN
            V_DESC := V_DESC || 'DTINIPREVAUD= ' || NVL(TO_CHAR(:NEW.DTINIPREVAUD, 'DD/MM/YYYY'),'') || ' ';
         END IF;

         IF (:NEW.DTFINPREVAUD <> :OLD.DTFINPREVAUD) THEN
            V_DESC := V_DESC || 'DTFINPREVAUD= ' || NVL(TO_CHAR(:NEW.DTFINPREVAUD, 'DD/MM/YYYY'),'') || ' ';
         END IF;

         IF (:NEW.DTINIREALAUD <> :OLD.DTINIREALAUD) THEN
            V_DESC := V_DESC || 'DTINIREALAUD= ' || NVL(TO_CHAR(:NEW.DTINIREALAUD, 'DD/MM/YYYY'),'') || ' ';
         END IF;

         IF (:NEW.DTFINREALAUD <> :OLD.DTFINREALAUD) THEN
            V_DESC := V_DESC || 'DTFINREALAUD= ' || NVL(TO_CHAR(:NEW.DTFINREALAUD, 'DD/MM/YYYY'),'') || ' ';
         END IF;

         IF (:NEW.QTTEMPVALAUD <> :OLD.QTTEMPVALAUD) THEN
            V_DESC := V_DESC || 'QTTEMPVALAUD= ' || TO_CHAR(:NEW.QTTEMPVALAUD) || ' ';
         END IF;

         IF (:NEW.IDUNTEMPVAUD <> :OLD.IDUNTEMPVAUD) THEN
            V_DESC := V_DESC || 'IDUNTEMPVAUD= ' || NVL(:NEW.IDUNTEMPVAUD,'') || ' ';
         END IF;

         IF (:NEW.DTVALIDAUDIT <> :OLD.DTVALIDAUDIT) THEN
            V_DESC := V_DESC || 'DTVALIDAUDIT= ' || NVL(TO_CHAR(:NEW.DTVALIDAUDIT, 'DD/MM/YYYY'),'') || ' ';
         END IF;

         IF (:NEW.NMPESCONTAUD <> :OLD.NMPESCONTAUD) THEN
            V_DESC := V_DESC || 'NMPESCONTAUD= ' || :NEW.NMPESCONTAUD || ' ';
         END IF;

         IF (:NEW.CDTIPORESU <> :OLD.CDTIPORESU) THEN
            V_DESC := V_DESC || 'CDTIPORESU=  ' || :NEW.CDTIPORESU || ' ';
         END IF;

         IF (:NEW.DSREFEAUDIT <> :OLD.DSREFEAUDIT) THEN
            V_DESC := V_DESC || 'DSREFEAUDIT= ' || :NEW.DSREFEAUDIT || ' ';
         END IF;

         IF (:NEW.DSAUDITORIA <> :OLD.DSAUDITORIA) THEN
            V_DESC := V_DESC || 'DSAUDITORIA= ' || :NEW.DSAUDITORIA || ' ';
         END IF;

         IF (:NEW.IDORIGAUDIT <> :OLD.IDORIGAUDIT) THEN
            V_DESC := V_DESC || 'IDORIGAUDIT= ' || :NEW.IDORIGAUDIT || ' ';
         END IF;

         IF (:NEW.CDSETSOLIAUD <> :OLD.CDSETSOLIAUD) THEN
            V_DESC := V_DESC || 'CDSETSOLIAUD= ' || :NEW.CDSETSOLIAUD || ' ';
         END IF;

         IF (:NEW.CDSETRECEAUD <> :OLD.CDSETRECEAUD) THEN
            V_DESC := V_DESC || 'CDSETRECEAUD= ' || :NEW.CDSETRECEAUD || ' ';
         END IF;

         IF (:NEW.CDSETEXECAUD <> :OLD.CDSETEXECAUD) THEN
            V_DESC := V_DESC || 'CDSETEXECAUD= ' || :NEW.CDSETEXECAUD || ' ' ;
         END IF;

         IF (:NEW.NRLOTEESTQ <> :OLD.NRLOTEESTQ) THEN
            V_DESC := V_DESC || 'NRLOTEESTQ= ' || :NEW.NRLOTEESTQ || ' ' ;
         END IF;

         IF (:NEW.NRSUBLOTE <> :OLD.NRSUBLOTE) THEN
            V_DESC := V_DESC || 'NRSUBLOTE= ' || :NEW.NRSUBLOTE || ' ' ;
         END IF;

         IF (:NEW.NMOPEINCAUD <> :OLD.NMOPEINCAUD) THEN
            V_DESC := V_DESC || 'NMOPEINCAUD= ' || :NEW.NMOPEINCAUD || ' ' ;
         END IF;

         IF (:NEW.CDPRODUTO <> :OLD.CDPRODUTO) THEN
            V_DESC := V_DESC || 'CDPRODUTO= ' || :NEW.CDPRODUTO || ' ' ;
         END IF;

         IF (:NEW.NRORDPROD <> :OLD.NRORDPROD) THEN
            V_DESC := V_DESC || 'NRORDPROD= ' || NVL(:NEW.NRORDPROD,'') || ' ' ;
         END IF;

         IF (:NEW.NRSUBORDPROD <> :OLD.NRSUBORDPROD) THEN
            V_DESC := V_DESC || 'NRSUBORDPROD= ' || NVL(:NEW.NRSUBORDPROD,'') || ' ' ;
         END IF;

         IF (:NEW.CDETAPAPROD <> :OLD.CDETAPAPROD) THEN
            V_DESC := V_DESC || 'CDETAPAPROD= ' || NVL(:NEW.CDETAPAPROD,'') || ' ';
         END IF;

         IF (:NEW.CDEQUIPPRO <> :OLD.CDEQUIPPRO) THEN
            V_DESC := V_DESC || 'CDEQUIPPRO= ' || NVL(:NEW.CDEQUIPPRO,'') || ' ';
         END IF;

         IF (:NEW.IDSTATUSAUDI <> :OLD.IDSTATUSAUDI) THEN
            V_DESC := V_DESC || 'IDSTATUSAUDI= ' || NVL(:NEW.IDSTATUSAUDI,'') || ' ';
         END IF;

         IF (:NEW.VRAPRPRODAUD <> :OLD.VRAPRPRODAUD) THEN
            V_DESC := V_DESC || 'VRAPRPRODAUD= ' || NVL(:NEW.VRAPRPRODAUD,'') || ' ';
         END IF;

         IF (:NEW.NRPRIORAUDI <> :OLD.NRPRIORAUDI) THEN
            V_DESC := V_DESC || 'NRPRIORAUDI= ' || NVL(:NEW.NRPRIORAUDI,'') || ' ';
         END IF;

         IF (:NEW.NRLANCTONF <> :OLD.NRLANCTONF) THEN
            V_DESC := V_DESC || 'NRLANCTONF= ' || NVL(:NEW.NRLANCTONF,'') || ' ';
         END IF;

         IF (:NEW.NRSEQITPROD <> :OLD.NRSEQITPROD) THEN
            V_DESC := V_DESC || 'NRSEQITPROD= ' || NVL(:NEW.NRSEQITPROD,'') || ' ';
         END IF;

         IF (:NEW.DTAMOSAUDI <> :OLD.DTAMOSAUDI) THEN
            V_DESC := V_DESC || 'DTAMOSAUDI= ' || NVL(TO_CHAR(:NEW.DTAMOSAUDI, 'DD/MM/YYYY'),'') || ' ';
         END IF;

         IF (:NEW.DTVALANA <> :OLD.DTVALANA) THEN
            V_DESC := V_DESC || 'DTVALANA= ' || NVL(TO_CHAR(:NEW.DTVALANA, 'DD/MM/YYYY'),'') || ' ';
         END IF;

         IF (:NEW.QTHRAUDIT <> :OLD.QTHRAUDIT) THEN
            V_DESC := V_DESC || 'QTHRAUDIT= ' || TO_CHAR(:NEW.QTHRAUDIT) || ' ';
         END IF;

         IF (:NEW.IDLIBERAUDIT <> :OLD.IDLIBERAUDIT) THEN
            V_DESC := V_DESC || 'IDLIBERAUDIT= ' || NVL(:NEW.IDLIBERAUDIT,'') || ' ';
         END IF;

         IF (:NEW.CDPRODANTE <> :OLD.CDPRODANTE) THEN
            V_DESC := V_DESC || 'CDPRODANTE= ' || NVL(:NEW.CDPRODANTE,'') || ' ';
         END IF;

         IF (:NEW.CDPROSPECT <> :OLD.CDPROSPECT) THEN
            V_DESC := V_DESC || 'CDPROSPECT= ' || :NEW.CDPROSPECT || ' ';
         END IF;

         IF (:NEW.NRORDIMPAUD <> :OLD.NRORDIMPAUD) THEN
            V_DESC := V_DESC || 'NRORDIMPAUD=  ' || :NEW.NRORDIMPAUD || ' ';
         END IF;

         IF (:NEW.QTAMOSAUDI <> :OLD.QTAMOSAUDI) THEN
            V_DESC := V_DESC || 'QTAMOSAUDI= ' || :NEW.QTAMOSAUDI || ' ';
         END IF;

         IF (:NEW.CDFILIALNF <> :OLD.CDFILIALNF) THEN
            V_DESC := V_DESC || 'CDFILIALNF= ' || :NEW.CDFILIALNF || ' ';
         END IF;

         IF (:NEW.CDFILIORCA <> :OLD.CDFILIORCA) THEN
            V_DESC := V_DESC || 'CDFILIORCA= ' || :NEW.CDFILIORCA || ' ';
         END IF;

         IF (:NEW.NRORCAEVENTO <> :OLD.NRORCAEVENTO) THEN
            V_DESC := V_DESC || 'NRORCAEVENTO= ' || :NEW.NRORCAEVENTO || ' ';
         END IF;

         IF (:NEW.NRSEQORCAEVE <> :OLD.NRSEQORCAEVE) THEN
            V_DESC := V_DESC || 'NRSEQORCAEVE= ' || :NEW.NRSEQORCAEVE || ' ';
         END IF;

         IF (:NEW.CDOPERRESPALT <> :OLD.CDOPERRESPALT) THEN
            V_DESC := V_DESC || 'Ope. Aut.= ' || :NEW.CDOPERRESPALT || ' ' ;
         END IF;

         IF (:NEW.CDJUSTALTERA <> :OLD.CDJUSTALTERA) THEN
            V_DESC := V_DESC || 'Just.:= ' || :NEW.CDJUSTALTERA || ' ' ;
         END IF;

         IF (:NEW.IDAUDIPIL <> :OLD.IDAUDIPIL) THEN
            V_DESC := V_DESC || 'IDAUDIPIL= ' || :NEW.IDAUDIPIL || ' ' ;
         END IF;

         IF (:NEW.IDTIPOANA <> :OLD.IDTIPOANA) THEN
            V_DESC := V_DESC || 'IDTIPOANA= ' || :NEW.IDTIPOANA || ' ' ;
         END IF;

         IF (:NEW.QTMOVIMENTADA <> :OLD.QTMOVIMENTADA) THEN
            V_DESC := V_DESC || 'QTMOVIMENTADA= ' || :NEW.QTMOVIMENTADA || ' ' ;
         END IF;

         IF (:NEW.IDGERADOJOB <> :OLD.IDGERADOJOB) THEN
            V_DESC := V_DESC || 'IDGERADOJOB= ' || :NEW.IDGERADOJOB || ' ' ;
         END IF;

         IF (:NEW.IDGERADOREANA <> :OLD.IDGERADOREANA) THEN
            V_DESC := V_DESC || 'IDGERADOREANA= ' || :NEW.IDGERADOREANA || ' ' ;
         END IF;

         IF (:NEW.IDENVIAVISO <> :OLD.IDENVIAVISO) THEN
            V_DESC := V_DESC || 'IDENVIAVISO= ' || :NEW.IDENVIAVISO || ' ' ;
         END IF;

         IF (:NEW.IDCOMPATIBILIDADE <> :OLD.IDCOMPATIBILIDADE) THEN
            V_DESC := V_DESC || 'IDCOMPATIBILIDADE= ' || :NEW.IDCOMPATIBILIDADE || ' ' ;
         END IF;

         IF (:NEW.CDOPERLIBAUD <> :OLD.CDOPERLIBAUD) THEN
            V_DESC := V_DESC || 'CDOPERLIBAUD= ' || :NEW.CDOPERLIBAUD || ' ' ;
         END IF;

         IF (:NEW.QTESTOQATUAL <> :OLD.QTESTOQATUAL) THEN
            V_DESC := V_DESC || 'QTESTOQATUAL= ' || :NEW.QTESTOQATUAL || ' ' ;
         END IF;

         IF (:NEW.QTESTQAPROVA <> :OLD.QTESTQAPROVA) THEN
            V_DESC := V_DESC || 'QTESTQAPROVA= ' || :NEW.QTESTQAPROVA || ' ' ;
         END IF;

         IF (:NEW.QTESTQREPROVA <> :OLD.QTESTQREPROVA) THEN
            V_DESC := V_DESC || 'QTESTQREPROVA= ' || :NEW.QTESTQREPROVA || ' ' ;
         END IF;

         IF (:NEW.NRSUBLOTEPARC <> :OLD.NRSUBLOTEPARC) THEN
            V_DESC := V_DESC || 'NRSUBLOTEPARC= ' || :NEW.NRSUBLOTEPARC || ' ' ;
         END IF;

         V_ITPESQ := :NEW.CDFILIAL || :NEW.NRAUDITORIA;

          V_IDTIPOOPER := '2';
          V_CDFILLOGOPER := :NEW.CDFILIAL;

      END IF;

   IF DELETING  THEN
      /*IF :OLD.CDFILIAL IS NOT NULL THEN
         V_DESC := V_DESC || 'Filial= ' || NVL(:OLD.CDFILIAL,'') || ' ' ;
      END IF;

      IF :OLD.NRAUDITORIA IS NOT NULL THEN
         V_DESC := V_DESC || 'NrAudit.= ' || NVL(:OLD.NRAUDITORIA,'') || ' ' ;
      END IF;

      IF :OLD.CDOPEINCAUDI IS NOT NULL THEN
         V_DESC := V_DESC || 'CDOPEINCAUDI= ' || NVL(:OLD.CDOPEINCAUDI,'') || ' ';
      END IF;

      IF :OLD.DTINCLAUDIT IS NOT NULL THEN
         V_DESC := V_DESC || 'DTINCLAUDIT= ' || NVL(:OLD.DTINCLAUDIT,'') || ' ';
      END IF;

      IF :OLD.IDTPAUDITADO IS NOT NULL THEN
         V_DESC := V_DESC || 'IDTPAUDITADO= ' || NVL(:OLD.IDTPAUDITADO,'') || ' ';
      END IF;

      IF :OLD.CDCLIENTE IS NOT NULL THEN
         V_DESC := V_DESC || 'CDCLIENTE= ' || NVL(:OLD.CDCLIENTE,'') || ' ';
      END IF;

      IF :OLD.CDFORNECED IS NOT NULL THEN
         V_DESC := V_DESC || 'CDFORNECED= ' || NVL(:OLD.CDFORNECED,'') || ' ';
      END IF;

      IF :OLD.CDTIPAUDIT IS NOT NULL THEN
         V_DESC := V_DESC || 'CDTIPAUDIT= ' || NVL(:OLD.CDTIPAUDIT,'') || ' ';
      END IF;

      IF :OLD.CDCRITAVAFIN IS NOT NULL THEN
         V_DESC := V_DESC || 'CDCRITAVAFIN= ' || NVL(:OLD.CDCRITAVAFIN,'') || ' ';
      END IF;

      IF :OLD.DTINIPREVAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'DTINIPREVAUD= ' || NVL(TO_CHAR(:OLD.DTINIPREVAUD, 'DD/MM/YYYY'),'') || ' ';
      END IF;

      IF :OLD.DTFINPREVAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'DTFINPREVAUD= ' || NVL(TO_CHAR(:OLD.DTFINPREVAUD, 'DD/MM/YYYY'),'') || ' ';
      END IF;

      IF :OLD.DTINIREALAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'DTINIREALAUD= ' || NVL(TO_CHAR(:OLD.DTINIREALAUD, 'DD/MM/YYYY'),'') || ' ';
      END IF;

      IF :OLD.DTFINREALAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'DTFINREALAUD= ' || NVL(TO_CHAR(:OLD.DTFINREALAUD, 'DD/MM/YYYY'),'') || ' ';
      END IF;

      IF :OLD.QTTEMPVALAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'QTTEMPVALAUD= ' || TO_CHAR(:OLD.QTTEMPVALAUD) || ' ';
      END IF;

      IF :OLD.IDUNTEMPVAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'IDUNTEMPVAUD= ' || NVL(:OLD.IDUNTEMPVAUD,'') || ' ';
      END IF;

      IF :OLD.DTVALIDAUDIT IS NOT NULL THEN
         V_DESC := V_DESC || 'DTVALIDAUDIT= ' || NVL(TO_CHAR(:OLD.DTVALIDAUDIT, 'DD/MM/YYYY'),'') || ' ';
      END IF;

      IF :OLD.NMPESCONTAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'NMPESCONTAUD= ' || :OLD.NMPESCONTAUD || ' ';
      END IF;

      IF :OLD.CDTIPORESU IS NOT NULL THEN
         V_DESC := V_DESC || 'CDTIPORESU=  ' || :OLD.CDTIPORESU || ' ';
      END IF;

      IF :OLD.DSREFEAUDIT IS NOT NULL THEN
         V_DESC := V_DESC || 'DSREFEAUDIT= ' || :OLD.DSREFEAUDIT || ' ';
      END IF;

      IF :OLD.DSAUDITORIA IS NOT NULL THEN
         V_DESC := V_DESC || 'DSAUDITORIA= ' || :OLD.DSAUDITORIA || ' ';
      END IF;

      IF :OLD.IDORIGAUDIT IS NOT NULL THEN
         V_DESC := V_DESC || 'IDORIGAUDIT= ' || :OLD.IDORIGAUDIT || ' ';
      END IF;

      IF :OLD.CDSETSOLIAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'CDSETSOLIAUD= ' || :OLD.CDSETSOLIAUD || ' ';
      END IF;

      IF :OLD.CDSETRECEAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'CDSETRECEAUD= ' || :OLD.CDSETRECEAUD || ' ';
      END IF;

      IF :OLD.CDSETEXECAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'CDSETEXECAUD= ' || :OLD.CDSETEXECAUD || ' ' ;
      END IF;

      IF :OLD.NRLOTEESTQ IS NOT NULL THEN
         V_DESC := V_DESC || 'NRLOTEESTQ= ' || :OLD.NRLOTEESTQ || ' ' ;
      END IF;

      IF :OLD.NRSUBLOTE IS NOT NULL THEN
         V_DESC := V_DESC || 'NRSUBLOTE= ' || :OLD.NRSUBLOTE || ' ' ;
      END IF;

      IF :OLD.NMOPEINCAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'NMOPEINCAUD= ' || :OLD.NMOPEINCAUD || ' ' ;
      END IF;

      IF :OLD.CDPRODUTO IS NOT NULL THEN
         V_DESC := V_DESC || 'CDPRODUTO= ' || :OLD.CDPRODUTO || ' ' ;
      END IF;

      IF :OLD.NRORDPROD IS NOT NULL THEN
         V_DESC := V_DESC || 'NRORDPROD= ' || NVL(:OLD.NRORDPROD,'') || ' ' ;
      END IF;

      IF :OLD.NRSUBORDPROD IS NOT NULL THEN
         V_DESC := V_DESC || 'NRSUBORDPROD= ' || NVL(:OLD.NRSUBORDPROD,'') || ' ' ;
      END IF;

      IF :OLD.CDETAPAPROD IS NOT NULL THEN
         V_DESC := V_DESC || 'CDETAPAPROD= ' || NVL(:OLD.CDETAPAPROD,'') || ' ';
      END IF;

      IF :OLD.CDEQUIPPRO IS NOT NULL THEN
         V_DESC := V_DESC || 'CDEQUIPPRO= ' || NVL(:OLD.CDEQUIPPRO,'') || ' ';
      END IF;

      IF :OLD.IDSTATUSAUDI IS NOT NULL THEN
         V_DESC := V_DESC || 'IDSTATUSAUDI= ' || NVL(:OLD.IDSTATUSAUDI,'') || ' ';
      END IF;

      IF :OLD.VRAPRPRODAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'VRAPRPRODAUD= ' || NVL(:OLD.VRAPRPRODAUD,'') || ' ';
      END IF;

      IF :OLD.NRPRIORAUDI IS NOT NULL THEN
         V_DESC := V_DESC || 'NRPRIORAUDI= ' || NVL(:OLD.NRPRIORAUDI,'') || ' ';
      END IF;

      IF :OLD.NRLANCTONF IS NOT NULL THEN
         V_DESC := V_DESC || 'NRLANCTONF= ' || NVL(:OLD.NRLANCTONF,'') || ' ';
      END IF;

      IF :OLD.NRSEQITPROD IS NOT NULL THEN
         V_DESC := V_DESC || 'NRSEQITPROD= ' || NVL(:OLD.NRSEQITPROD,'') || ' ';
      END IF;

      IF :OLD.DTAMOSAUDI IS NOT NULL THEN
         V_DESC := V_DESC || 'DTAMOSAUDI= ' || NVL(TO_CHAR(:OLD.DTAMOSAUDI, 'DD/MM/YYYY'),'') || ' ';
      END IF;

      IF :OLD.DTVALANA IS NOT NULL THEN
         V_DESC := V_DESC || 'DTVALANA= ' || NVL(TO_CHAR(:OLD.DTVALANA, 'DD/MM/YYYY'),'') || ' ';
      END IF;

      IF :OLD.QTHRAUDIT IS NOT NULL THEN
         V_DESC := V_DESC || 'QTHRAUDIT= ' || TO_CHAR(:OLD.QTHRAUDIT) || ' ';
      END IF;

      IF :OLD.IDLIBERAUDIT IS NOT NULL THEN
         V_DESC := V_DESC || 'IDLIBERAUDIT= ' || NVL(:OLD.IDLIBERAUDIT,'') || ' ';
      END IF;

      IF :OLD.CDPRODANTE IS NOT NULL THEN
         V_DESC := V_DESC || 'CDPRODANTE= ' || NVL(:OLD.CDPRODANTE,'') || ' ';
      END IF;

      IF :OLD.CDPROSPECT IS NOT NULL THEN
         V_DESC := V_DESC || 'CDPROSPECT= ' || :OLD.CDPROSPECT || ' ';
      END IF;

      IF :OLD.NRORDIMPAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'NRORDIMPAUD=  ' || :OLD.NRORDIMPAUD || ' ';
      END IF;

      IF :OLD.QTAMOSAUDI IS NOT NULL THEN
         V_DESC := V_DESC || 'QTAMOSAUDI= ' || :OLD.QTAMOSAUDI || ' ';
      END IF;

      IF :OLD.CDFILIALNF IS NOT NULL THEN
         V_DESC := V_DESC || 'CDFILIALNF= ' || :OLD.CDFILIALNF || ' ';
      END IF;

      IF :OLD.CDFILIORCA IS NOT NULL THEN
         V_DESC := V_DESC || 'CDFILIORCA= ' || :OLD.CDFILIORCA || ' ';
      END IF;

      IF :OLD.NRORCAEVENTO IS NOT NULL THEN
         V_DESC := V_DESC || 'NRORCAEVENTO= ' || :OLD.NRORCAEVENTO || ' ';
      END IF;

      IF :OLD.NRSEQORCAEVE IS NOT NULL THEN
         V_DESC := V_DESC || 'NRSEQORCAEVE= ' || :OLD.NRSEQORCAEVE || ' ';
      END IF; */

      IF :OLD.CDOPERRESPALT IS NOT NULL THEN
         V_DESC := V_DESC || 'Ope. Aut.= ' || :OLD.CDOPERRESPALT || ' ' ;
      END IF;

      IF :OLD.CDJUSTALTERA IS NOT NULL THEN
         V_DESC := V_DESC || 'Just.:= ' || :OLD.CDJUSTALTERA || ' ' ;
      END IF;

      /*IF :OLD.IDAUDIPIL IS NOT NULL THEN
         V_DESC := V_DESC || 'IDAUDIPIL= ' || :OLD.IDAUDIPIL || ' ' ;
      END IF;

      IF :OLD.IDTIPOANA IS NOT NULL THEN
         V_DESC := V_DESC || 'IDTIPOANA= ' || :OLD.IDTIPOANA || ' ' ;
      END IF;

      IF :OLD.QTMOVIMENTADA IS NOT NULL THEN
         V_DESC := V_DESC || 'QTMOVIMENTADA= ' || :OLD.QTMOVIMENTADA || ' ' ;
      END IF;

      IF :OLD.IDGERADOJOB IS NOT NULL THEN
         V_DESC := V_DESC || 'IDGERADOJOB= ' || :OLD.IDGERADOJOB || ' ' ;
      END IF;

      IF :OLD.IDGERADOREANA IS NOT NULL THEN
         V_DESC := V_DESC || 'IDGERADOREANA= ' || :OLD.IDGERADOREANA || ' ' ;
      END IF;

      IF :OLD.IDENVIAVISO IS NOT NULL THEN
         V_DESC := V_DESC || 'IDENVIAVISO= ' || :OLD.IDENVIAVISO || ' ' ;
      END IF;

      IF :OLD.IDCOMPATIBILIDADE IS NOT NULL THEN
         V_DESC := V_DESC || 'IDCOMPATIBILIDADE= ' || :OLD.IDCOMPATIBILIDADE || ' ' ;
      END IF;

      IF :OLD.CDOPERLIBAUD IS NOT NULL THEN
         V_DESC := V_DESC || 'CDOPERLIBAUD= ' || :OLD.CDOPERLIBAUD || ' ' ;
      END IF;

      IF :OLD.QTESTOQATUAL IS NOT NULL THEN
         V_DESC := V_DESC || 'QTESTOQATUAL= ' || :OLD.QTESTOQATUAL || ' ' ;
      END IF;

      IF :OLD.QTESTQAPROVA IS NOT NULL THEN
         V_DESC := V_DESC || 'QTESTQAPROVA= ' || :OLD.QTESTQAPROVA || ' ' ;
      END IF;

      IF :OLD.QTESTQREPROVA IS NOT NULL THEN
         V_DESC := V_DESC || 'QTESTQREPROVA= ' || :OLD.QTESTQREPROVA || ' ' ;
      END IF;

      IF :OLD.NRSUBLOTEPARC IS NOT NULL THEN
         V_DESC := V_DESC || 'NRSUBLOTEPARC= ' || :OLD.NRSUBLOTEPARC || ' ' ;
      END IF; */

      V_ITPESQ := :OLD.CDFILIAL || :OLD.NRAUDITORIA;

      V_IDTIPOOPER := '3';
      V_CDFILLOGOPER := :OLD.CDFILIAL;

   END IF;

   IF NOT (V_DESC IS NULL) THEN
 
      V_LENGTH := LENGTH(V_DESC);

      WHILE V_LENGTH >= V_CONT_LENGTH LOOP

         V_GRAV_DESC := SUBSTR(V_DESC, V_CONT_LENGTH, 300);
         V_CONT_LENGTH := V_CONT_LENGTH + 300;

         INSERT INTO LOGOPERA ( NMTABELA, DTOPERACAO, NMRESPOPER,
                                IDTIPOOPER,   DSOPERACAO, CDPESQITEM,
                                DSRDMUSUOPER, DSENDUSUOPER, DSNMUSUOPER,
                                DSMETUSUOPER, CDORESPOPER, CDFILLOGOPER)
                      VALUES  ('AUDITORIA', SYSDATE ,    NVL(V_NMOPERADOR,' '),
                                V_IDTIPOOPER,   V_GRAV_DESC, V_ITPESQ,
                                V_DSSERVERRDM, V_DSREMOTEADDR,  V_DSREMOTEHOST,
                                V_DSSERVMETHOD,   V_DSREMOTEOPER, V_CDFILLOGOPER);

      END LOOP;
   END IF;
END;