CREATE OR REPLACE TRIGGER LOG_GER_INSCRESTAD
AFTER DELETE OR INSERT OR UPDATE
ON INSCRESTAD 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_USUARIO      VARCHAR2(40);
  V_TIPO         VARCHAR2(1);
  V_ITPESQ       VARCHAR2(40);
  V_DESC         VARCHAR2(500);
  V_CDFILLOGOPER VARCHAR2(4);
  V_DTOPER       DATE;
BEGIN
   V_TIPO := '0';
   V_DESC := '';
   V_CDFILLOGOPER := '';

   IF DELETING THEN
      IF :OLD.CDEMPRESA IS NOT NULL THEN
         V_DESC := V_DESC || 'CDEmpresa=' || :OLD.CDEMPRESA;
      END IF;

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

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

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

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

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

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

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

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

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

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

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

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

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

      IF :OLD.NRSERIECERTIFIC IS NOT NULL THEN
         V_DESC := V_DESC || 'Num.Certificado=' || :OLD.NRSERIECERTIFIC;
      END IF;
      
      IF :OLD.IDTPIMPRESDANFE IS NOT NULL THEN
         V_DESC := V_DESC || 'Impr.Danfe=' || :OLD.IDTPIMPRESDANFE;
      END IF;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      IF :OLD.IDREALIESTAPURCRED IS NOT NULL THEN
         V_DESC := V_DESC || 'EstCPDevol='   || :OLD.IDREALIESTAPURCRED;
      END IF;
      
      IF :OLD.CDAJUSTEDEVOL IS NOT NULL THEN
         V_DESC := V_DESC || 'CdAjDevolCP='   || :OLD.CDAJUSTEDEVOL;
      END IF;
      
      IF :OLD.CDAJUSTEDEVOLEST IS NOT NULL THEN
         V_DESC := V_DESC || 'CdAjEstEstCred='   || :OLD.CDAJUSTEDEVOLEST;
      END IF;

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

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

      IF :OLD.IDCALCESTCRED IS NOT NULL THEN
         V_DESC := V_DESC || 'EstCredDif='   || :OLD.IDCALCESTCRED;
      END IF;
      
      IF :OLD.DTINIESTCRED IS NOT NULL THEN
         V_DESC := V_DESC || 'DtIniEsstCred='   || :OLD.DTINIESTCRED;
      END IF;
      
      IF :OLD.IDCALCDIFENTFISC IS NOT NULL THEN
         V_DESC := V_DESC || 'IdCalcDifEntr='   || :OLD.IDCALCDIFENTFISC;
      END IF;
      
      IF :OLD.IDDIFERICMSANT IS NOT NULL THEN
         V_DESC := V_DESC || 'DifICMSAnt='   || :OLD.IDDIFERICMSANT;
      END IF;

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

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

      IF :OLD.CDCFOPESTAPUR IS NOT NULL THEN
         V_DESC := V_DESC || 'CfopEstApur='   || :OLD.CDCFOPESTAPUR;
      END IF;
      
      IF :OLD.VRALIQEFETIVA IS NOT NULL THEN
         V_DESC := V_DESC || 'AliqEfetivaEst='   || :OLD.VRALIQEFETIVA;
      END IF;
      
      IF :OLD.VRALIQINTERNA IS NOT NULL THEN
         V_DESC := V_DESC || 'AliqInternEst='   || :OLD.VRALIQINTERNA;
      END IF;

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

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

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

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

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

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

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

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

      V_TIPO         := '3';
      V_ITPESQ       := :OLD.CDEMPRESA||:OLD.CDINSCESTA;
      V_CDFILLOGOPER := :OLD.CDFILIAL;
   ELSE
      IF UPDATING THEN
         IF (NVL(:OLD.CDEMPRESA,'!')          <> NVL(:NEW.CDEMPRESA,'!'))          OR
            (NVL(:OLD.CDINSCESTA,'!')         <> NVL(:NEW.CDINSCESTA,'!'))         OR
            (NVL(:OLD.NMREPRINSEST,'!')       <> NVL(:NEW.NMREPRINSEST,'!'))       OR
            (NVL(:OLD.NRINSJURIEST,'!')       <> NVL(:NEW.NRINSJURIEST,'!'))       OR
            (NVL(:OLD.CDCSTDIG1SAI,'!')       <> NVL(:NEW.CDCSTDIG1SAI,'!'))       OR
            (NVL(:OLD.DSENDEIEST,'!')         <> NVL(:NEW.DSENDEIEST,'!'))         OR
            (NVL(:OLD.DSCOMPENDIES,'!')       <> NVL(:NEW.DSCOMPENDIES,'!'))       OR
            (NVL(:OLD.NRCEPIEST,'!')          <> NVL(:NEW.NRCEPIEST,'!'))          OR
            (NVL(:OLD.CDPAIS,'!')             <> NVL(:NEW.CDPAIS,'!'))             OR
            (NVL(:OLD.SGESTADO,'!')           <> NVL(:NEW.SGESTADO,'!'))           OR
            (NVL(:OLD.CDBAIRRO,'!')           <> NVL(:NEW.CDBAIRRO,'!'))           OR
            (NVL(:OLD.NMBAIRIEST,'!')         <> NVL(:NEW.NMBAIRIEST,'!'))         OR
            (NVL(:OLD.NRTELEIEST,'!')         <> NVL(:NEW.NRTELEIEST,'!'))         OR
            (NVL(:OLD.NRFAXIEST,'!')          <> NVL(:NEW.NRFAXIEST,'!'))          OR
            (NVL(:OLD.NRSERIECERTIFIC,'!')    <> NVL(:NEW.NRSERIECERTIFIC,'!'))    OR
            (NVL(:OLD.IDTPIMPRESDANFE,'!')    <> NVL(:NEW.IDTPIMPRESDANFE,'!'))    OR
            (NVL(:OLD.IDTPAMBIENTENFE,'!')    <> NVL(:NEW.IDTPAMBIENTENFE,'!'))    OR
            (NVL(:OLD.IDSUGREGSTENTR,'!')     <> NVL(:NEW.IDSUGREGSTENTR,'!'))     OR
            (NVL(:OLD.CDENCARGOST,'!')        <> NVL(:NEW.CDENCARGOST,'!'))        OR
            (NVL(:OLD.DTINIVIGIEST,TO_DATE('01/01/1900', 'DD/MM/YYYY')) <> NVL(:NEW.DTINIVIGIEST,TO_DATE('01/01/1900', 'DD/MM/YYYY'))) OR
            (NVL(:OLD.DTFIMVIGIEST,TO_DATE('01/01/1900', 'DD/MM/YYYY')) <> NVL(:NEW.DTFIMVIGIEST,TO_DATE('01/01/1900', 'DD/MM/YYYY'))) OR
	    (NVL(:OLD.VRPERCREDST,0)          <> NVL(:NEW.VRPERCREDST,0))          OR
            (NVL(:OLD.IDUTALIQINTOPPRES,'!')  <> NVL(:NEW.IDUTALIQINTOPPRES,'!'))  OR
            (NVL(:OLD.IDUTCARGATRIB,'!')      <> NVL(:NEW.IDUTCARGATRIB,'!'))      OR
            (NVL(:OLD.IDCREDDEBNORM,'!')      <> NVL(:NEW.IDCREDDEBNORM,'!'))      OR
            (NVL(:OLD.IDENVBCSPEDGIA,'!')     <> NVL(:NEW.IDENVBCSPEDGIA,'!'))     OR
            (NVL(:OLD.IDOUTCREDDEB,'!')       <> NVL(:NEW.IDOUTCREDDEB,'!'))       OR
            (NVL(:OLD.CDAJSTCREDCARGA,'!')    <> NVL(:NEW.CDAJSTCREDCARGA,'!'))    OR
            (NVL(:OLD.CDAJSTDEBICARGA,'!')    <> NVL(:NEW.CDAJSTDEBICARGA,'!'))    OR
            (NVL(:OLD.IDESTODBCRDEV,'!')      <> NVL(:NEW.IDESTODBCRDEV,'!'))      OR
            (NVL(:OLD.CDAJOUTCREDDEV,'!')     <> NVL(:NEW.CDAJOUTCREDDEV,'!'))     OR
            (NVL(:OLD.CDAJESTODEBDEV,'!')     <> NVL(:NEW.CDAJESTODEBDEV,'!'))     OR
            (NVL(:NEW.IDAPURLUCPRE,'!')       <> NVL(:OLD.IDAPURLUCPRE,'!'))       OR
            (NVL(:NEW.IDCALCULOCP,'!')        <> NVL(:OLD.IDCALCULOCP,'!'))        OR
            (NVL(:NEW.CDAJCREDPRES,'!')       <> NVL(:OLD.CDAJCREDPRES,'!'))       OR
            (NVL(:NEW.IDUTSUBAPURCP,'!')      <> NVL(:OLD.IDUTSUBAPURCP,'!'))      OR
            (NVL(:NEW.IDNCONSPFCREDPRES,'!')  <> NVL(:OLD.IDNCONSPFCREDPRES,'!'))  OR
            (NVL(:NEW.IDINDICSUBAPURCP,'!')   <> NVL(:OLD.IDINDICSUBAPURCP,'!'))   OR
            (NVL(:NEW.CDAJESTORNOCP,'!')      <> NVL(:OLD.CDAJESTORNOCP,'!'))      OR
            (NVL(:NEW.IDREALIESTAPURCRED,'!') <> NVL(:OLD.IDREALIESTAPURCRED,'!')) OR
            (NVL(:NEW.CDAJUSTEDEVOL,'!')      <> NVL(:OLD.CDAJUSTEDEVOL,'!'))      OR
            (NVL(:NEW.CDAJUSTEDEVOLEST,'!')   <> NVL(:OLD.CDAJUSTEDEVOLEST,'!'))   OR
            (NVL(:NEW.VRALIQTOTALSAIDA,0)     <> NVL(:OLD.VRALIQTOTALSAIDA,0))     OR
            (NVL(:NEW.VRALIQIMPOSREC,0)       <> NVL(:OLD.VRALIQIMPOSREC,0))       OR
            (NVL(:NEW.IDCALCESTCRED,'!')      <> NVL(:OLD.IDCALCESTCRED,'!'))      OR
            (NVL(:NEW.DTINIESTCRED,TO_DATE('01/01/1900', 'DD/MM/YYYY')) <> NVL(:OLD.DTINIESTCRED,TO_DATE('01/01/1900', 'DD/MM/YYYY'))) OR
            (NVL(:NEW.IDCALCDIFENTFISC,'!')   <> NVL(:OLD.IDCALCDIFENTFISC,'!'))   OR
            (NVL(:NEW.IDDIFERICMSANT,'!')     <> NVL(:OLD.IDDIFERICMSANT,'!'))     OR
            (NVL(:NEW.IDREALIESTAPUR,'!')     <> NVL(:OLD.IDREALIESTAPUR,'!'))     OR
            (NVL(:NEW.CDTPOPERESTAPUR,'!')    <> NVL(:OLD.CDTPOPERESTAPUR,'!'))    OR
            (NVL(:NEW.CDCFOPESTAPUR,'!')      <> NVL(:OLD.CDCFOPESTAPUR,'!'))      OR
            (NVL(:NEW.VRALIQEFETIVA,0)        <> NVL(:OLD.VRALIQEFETIVA,0))        OR
            (NVL(:NEW.VRALIQINTERNA,0)        <> NVL(:OLD.VRALIQINTERNA,0))        OR
            (NVL(:NEW.CDAJUSTESTAPUR,'!')     <> NVL(:OLD.CDAJUSTESTAPUR,'!'))     OR
            (NVL(:NEW.IDESTAPURCREDIMPO,'!')  <> NVL(:OLD.IDESTAPURCREDIMPO,'!'))  OR
            (NVL(:NEW.IDSUBAPURPRODIMP,'!')   <> NVL(:OLD.IDSUBAPURPRODIMP,'!'))   OR
            (NVL(:NEW.IDINDSUBAPURIMP,'!')    <> NVL(:OLD.IDINDSUBAPURIMP,'!'))    OR
            (NVL(:NEW.CDAJESTORCPIMPO,'!')    <> NVL(:OLD.CDAJESTORCPIMPO,'!'))    OR
            (NVL(:NEW.CDAJUSTEDEVOLIMPO,'!')  <> NVL(:OLD.CDAJUSTEDEVOLIMPO,'!'))  OR
            (NVL(:NEW.CDAJDEVOLESTIMPO,'!')   <> NVL(:OLD.CDAJDEVOLESTIMPO,'!'))   OR
            (NVL(:NEW.IDTPMERCSUBAPURCP,'!')  <> NVL(:OLD.IDTPMERCSUBAPURCP,'!'))  THEN

            V_TIPO         := '2';
            V_ITPESQ       := :OLD.CDEMPRESA||:OLD.CDINSCESTA;
            V_CDFILLOGOPER := :OLD.CDFILIAL;
         END IF;
      ELSE
         V_TIPO         := '1';
         V_ITPESQ       := :NEW.CDEMPRESA||:NEW.CDINSCESTA;
         V_CDFILLOGOPER := :NEW.CDFILIAL;
      END IF;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      IF NVL(:NEW.NRSERIECERTIFIC, '!') <> NVL(:OLD.NRSERIECERTIFIC, '!') THEN
         V_DESC := V_DESC || 'Num.Certificado=' || :NEW.NRSERIECERTIFIC;
      END IF;

      IF NVL(:NEW.IDTPIMPRESDANFE, '!') <> NVL(:OLD.IDTPIMPRESDANFE, '!') THEN
         V_DESC := V_DESC || 'Impr.Danfe=' || :NEW.IDTPIMPRESDANFE;
      END IF;
      
      IF NVL(:NEW.IDTPAMBIENTENFE, '!') <> NVL(:OLD.IDTPAMBIENTENFE, '!')  THEN
         V_DESC := V_DESC || 'AmbienteNFE='   || :NEW.IDTPAMBIENTENFE;
      END IF;

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

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

      IF NVL(:NEW.DTINIVIGIEST,TO_DATE('01/01/1900', 'DD/MM/YYYY')) <> NVL(:OLD.DTINIVIGIEST,TO_DATE('01/01/1900', 'DD/MM/YYYY')) THEN
         V_DESC := V_DESC || 'VigenciaIni='   || :OLD.DTINIVIGIEST;
      END IF;

      IF NVL(:NEW.DTFIMVIGIEST,TO_DATE('01/01/1900', 'DD/MM/YYYY')) <> NVL(:OLD.DTFIMVIGIEST,TO_DATE('01/01/1900', 'DD/MM/YYYY')) THEN
         V_DESC := V_DESC || 'VigenciaFim='   || :OLD.DTFIMVIGIEST;
      END IF;
	  
      IF NVL(:NEW.VRPERCREDST,0) <> NVL(:OLD.VRPERCREDST,0) THEN
         V_DESC := V_DESC || ' VRPerCredST='   || :NEW.VRPERCREDST;
      END IF;

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

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

      IF NVL(:NEW.CDAJUSTEDEVOL,'!') <> NVL(:OLD.CDAJUSTEDEVOL,'!') THEN
         V_DESC := V_DESC || 'CdAjDevolCP='   || :OLD.CDAJUSTEDEVOL;
      END IF;
      
      IF NVL(:NEW.CDAJUSTEDEVOLEST,'!') <> NVL(:OLD.CDAJUSTEDEVOLEST,'!') THEN
         V_DESC := V_DESC || 'CdAjEstEstCred='   || :OLD.CDAJUSTEDEVOLEST;
      END IF;

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

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

      IF NVL(:NEW.IDCALCESTCRED,'!') <> NVL(:OLD.IDCALCESTCRED,'!') THEN
         V_DESC := V_DESC || 'EstCredDif='   || :OLD.IDCALCESTCRED;
      END IF;
      
      IF NVL(:NEW.DTINIESTCRED,TO_DATE('01/01/1900', 'DD/MM/YYYY')) <> NVL(:OLD.DTINIESTCRED,TO_DATE('01/01/1900', 'DD/MM/YYYY')) THEN
         V_DESC := V_DESC || 'DtIniEsstCred='   || :OLD.DTINIESTCRED;
      END IF;
      
      IF NVL(:NEW.IDCALCDIFENTFISC,'!') <> NVL(:OLD.IDCALCDIFENTFISC,'!') THEN
         V_DESC := V_DESC || 'IdCalcDifEntr='   || :OLD.IDCALCDIFENTFISC;
      END IF;
      
      IF NVL(:NEW.IDDIFERICMSANT,'!') <> NVL(:OLD.IDDIFERICMSANT,'!') THEN
         V_DESC := V_DESC || 'DifICMSAnt='   || :OLD.IDDIFERICMSANT;
      END IF;

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

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

      IF NVL(:NEW.CDCFOPESTAPUR,'!') <> NVL(:OLD.CDCFOPESTAPUR,'!') THEN
         V_DESC := V_DESC || 'CfopEstApur='   || :OLD.CDCFOPESTAPUR;
      END IF;
      
      IF NVL(:NEW.VRALIQEFETIVA,0) <> NVL(:OLD.VRALIQEFETIVA,0) THEN
         V_DESC := V_DESC || 'AliqEfetivaEst='   || :OLD.VRALIQEFETIVA;
      END IF;
      
      IF NVL(:NEW.VRALIQINTERNA,0) <> NVL(:OLD.VRALIQINTERNA,0) THEN
         V_DESC := V_DESC || 'AliqInternEst='   || :OLD.VRALIQINTERNA;
      END IF;

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

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

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

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

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

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

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

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

   IF V_TIPO <> '0' THEN
      NMUSUARIO(V_USUARIO);
      WEBTUNNING(V_DSREMOTEADDR,
                 V_DSREMOTEHOST,
                 V_DSSERVERRDM,
                 V_DSSERVMETHOD,
                 V_DSREMOTEOPER);
      IF NOT V_DESC IS NULL THEN
         IF NOT V_USUARIO IS NULL THEN
            V_DTOPER := SYSDATE;
            V_DESC   := SUBSTR(V_DESC, 1, 300);

            INSERT INTO LOGOPERA
               (NMTABELA,   DTOPERACAO, NMRESPOPER,
                IDTIPOOPER, CDPESQITEM, DSOPERACAO, CDFILLOGOPER,
                DSRDMUSUOPER, DSENDUSUOPER, DSNMUSUOPER,
                DSMETUSUOPER, CDORESPOPER)
            VALUES
               ('INSCRESTAD',  V_DTOPER, V_USUARIO,
                V_TIPO,      V_ITPESQ, V_DESC, V_CDFILLOGOPER,
                V_DSSERVERRDM, V_DSREMOTEADDR, V_DSREMOTEHOST,
                V_DSSERVMETHOD, V_DSREMOTEOPER);
         END IF;
      END IF;
   END IF;
END;
/
