DECLARE
   V_EXISTEDADOS INTEGER;
   V_ERROR VARCHAR2(255);
BEGIN

   V_EXISTEDADOS := 0;

   BEGIN
      SELECT COUNT(*)
        INTO V_EXISTEDADOS
        FROM INTG_NOTAFISCAL;
   EXCEPTION
      WHEN NO_DATA_FOUND THEN
         V_EXISTEDADOS := 0;
   END;

   IF V_EXISTEDADOS = 0 THEN

      BEGIN
         EXECUTE IMMEDIATE 'DROP TABLE INTG_CONTAPAGAR';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE TABLE INTG_CONTAPAGAR
                            (
                                CDFILIAL      VARCHAR2(30)           null    ,
                                NRLANCTONF    VARCHAR2(10)           null    ,
                                NRSEQVENPAG   VARCHAR2(2)            null    ,
                                NRPARCELAPAG  VARCHAR2(2)            null    ,
                                CDTPCTPAGAR   VARCHAR2(6)            null    ,
                                QTDIASVENPAG  NUMBER(10)             null    ,
                                DTORIGVENPAG  DATE                   null    ,
                                VRORIGPAG     FLOAT                  null    ,
                                CDEMPRESA     VARCHAR2(2)            null,
                                NRORG          NUMBER       DEFAULT SYS_CONTEXT(''nrorg_ctx'',''nrorg'') NOT NULL,
                                IDATIVO        VARCHAR2(1)  DEFAULT ''S''                                NOT NULL
                                   CONSTRAINT CKC_IDATIVO_INTG_CONTAPAGAR CHECK (IDATIVO IN (''S'',''N'')),
                                DTINCLUSAO     DATE                                                      NULL,
                                DTULTATU       DATE                                                      NULL,
                                NRORGINCLUSAO  NUMBER       DEFAULT 1                                    NULL,
                                CDOPERINCLUSAO VARCHAR2(12) DEFAULT ''1''                                NULL,
                                NRORGULTATU    NUMBER       DEFAULT 1                                    NULL,
                                CDOPERULTATU   VARCHAR2(12) DEFAULT ''1'')';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'DROP TABLE INTG_ITEMENCARGO';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
      EXECUTE IMMEDIATE 'CREATE TABLE INTG_ITEMENCARGO
                         (
                             CDFILIAL      VARCHAR2(30)           null    ,
                             NRLANCTONF    VARCHAR2(10)           null    ,
                             CDENCARGO     VARCHAR2(2)            null    ,
                             VRITEMENCA    FLOAT                  null
                             NRORG          NUMBER       DEFAULT SYS_CONTEXT(''nrorg_ctx'',''nrorg'') NOT NULL,
                             IDATIVO        VARCHAR2(1)  DEFAULT ''S''                                NOT NULL
                                CONSTRAINT CKC_IDATIVO_INTG_ITEMENCARGO CHECK (IDATIVO IN (''S'',''N'')),
                             DTINCLUSAO     DATE                                                      NULL,
                             DTULTATU       DATE                                                      NULL,
                             NRORGINCLUSAO  NUMBER       DEFAULT 1                                    NULL,
                             CDOPERINCLUSAO VARCHAR2(12) DEFAULT ''1''                                NULL,
                             NRORGULTATU    NUMBER       DEFAULT 1                                    NULL,
                             CDOPERULTATU   VARCHAR2(12) DEFAULT ''1'')';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'DROP TABLE INTG_TRABITPROIMPOS';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;
      
      BEGIN
         EXECUTE IMMEDIATE 'CREATE TABLE INTG_TRABITPROIMPOS
                            (
                                CDFILIAL      VARCHAR2(30)           null    ,
                                NRLANCTONF    VARCHAR2(10)           null    ,
                                NRSEQIMPOIT   VARCHAR2(4)            null    ,
                                CDIMPOSTOIT   VARCHAR2(2)            null    ,
                                VRCONTITIMP   FLOAT                  null    ,
                                VRPERREDBCIT  FLOAT                  null    ,
                                VRBASECALCIT  FLOAT                  null    ,
                                VRALIQITEM    FLOAT                  null    ,
                                VRIMPOSTOIT   FLOAT                  null    ,
                                CDFISCALIT    VARCHAR2(1)            null    ,
                                CDSITUTRIBIT  VARCHAR2(3)            null    ,
                                CDFISCOPERIT  VARCHAR2(11)           null    ,
                                NRITPROIMPOS  VARCHAR2(1)            null
                                NRORG          NUMBER       DEFAULT SYS_CONTEXT(''nrorg_ctx'',''nrorg'') NOT NULL,
                                IDATIVO        VARCHAR2(1)  DEFAULT ''S''                                NOT NULL
                                   CONSTRAINT CKC_IDATIVO_INTG_TRABITPROIMPOS CHECK (IDATIVO IN (''S'',''N'')),
                                DTINCLUSAO     DATE                                                      NULL,
                                DTULTATU       DATE                                                      NULL,
                                NRORGINCLUSAO  NUMBER       DEFAULT 1                                    NULL,
                                CDOPERINCLUSAO VARCHAR2(12) DEFAULT ''1''                                NULL,
                                NRORGULTATU    NUMBER       DEFAULT 1                                    NULL,
                                CDOPERULTATU   VARCHAR2(12) DEFAULT ''1'')';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;
      
      BEGIN
         EXECUTE IMMEDIATE 'DROP TABLE INTG_ITEMPRODUTO';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE TABLE INTG_ITEMPRODUTO
                            (
                                CDFILIAL      VARCHAR2(30)           null    ,
                                NRLANCTONF    VARCHAR2(10)           null    ,
                                NRSEQITPROD   VARCHAR2(4)            null    ,
                                CDPRODUTO     VARCHAR2(30)           null    ,
                                QTITEMPROD    FLOAT                  null    ,
                                VRUNITITEM    FLOAT                  null    ,
                                VRDESCITEM    FLOAT                  null    ,
                                VRTOTAITEM    FLOAT                  null    ,
                                VRBRUTITEM    FLOAT                  null    ,
                                VRCONTITEM    FLOAT                  null    ,
                                NRAUTOFORN    VARCHAR2(10)           null    ,
                                CDMARCA       VARCHAR2(5)            null    ,
                                DTPROGENTAF   DATE                   null    ,
                                VRDESPERITEM  FLOAT                  null    ,
                                CDFILIMOVI    VARCHAR2(30)           null    ,
                                CDALMOXARIFE  VARCHAR2(6)            null    ,
                                CDLOCALESTOQ  VARCHAR2(6)            null
                                NRORG          NUMBER       DEFAULT SYS_CONTEXT(''nrorg_ctx'',''nrorg'') NOT NULL,
                                IDATIVO        VARCHAR2(1)  DEFAULT ''S''                                NOT NULL
                                   CONSTRAINT CKC_IDATIVO_INTG_ITEMPRODUTO CHECK (IDATIVO IN (''S'',''N'')),
                                DTINCLUSAO     DATE                                                      NULL,
                                DTULTATU       DATE                                                      NULL,
                                NRORGINCLUSAO  NUMBER       DEFAULT 1                                    NULL,
                                CDOPERINCLUSAO VARCHAR2(12) DEFAULT ''1''                                NULL,
                                NRORGULTATU    NUMBER       DEFAULT 1                                    NULL,
                                CDOPERULTATU   VARCHAR2(12) DEFAULT ''1'')';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'DROP TABLE intg_inconsistencia';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'DROP TABLE INTG_NOTAFISCAL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE TABLE INTG_NOTAFISCAL
                            (
                                CDFILIAL      VARCHAR2(30)           null    ,
                                NRLANCTONF    VARCHAR2(10)           null    ,
                                CDEMPRESA     VARCHAR2(2)            null    ,
                                CDINSCESTA    VARCHAR2(16)           null    ,
                                IDTPIJURNF    VARCHAR2(1)            null    ,
                                NRINSJURNF    VARCHAR2(20)           null    ,
                                CDFORNECED    VARCHAR2(21)           null    ,
                                NRNOTAFISC    VARCHAR2(20)           null    ,
                                DTEMISSAO     DATE                   null    ,
                                DTENTRSAID    DATE                   null    ,
                                VRPRODUTOS    FLOAT                  null    ,
                                VRNOTAFISC    FLOAT                  null    ,
                                CDSERIEENTR   VARCHAR2(5)            null    ,
                                CDFILIRECE    VARCHAR2(30)           null    ,
                                IDIMPORTADA   VARCHAR2(1)            null    ,
                                DTLANCAMENNF  DATE                   null
                                NRORG          NUMBER       DEFAULT SYS_CONTEXT(''nrorg_ctx'',''nrorg'') NOT NULL,
                                IDATIVO        VARCHAR2(1)  DEFAULT ''S''                                NOT NULL
                                   CONSTRAINT CKC_IDATIVO_INTG_NOTAFISCAL CHECK (IDATIVO IN (''S'',''N'')),
                                DTINCLUSAO     DATE                                                      NULL,
                                DTULTATU       DATE                                                      NULL,
                                NRORGINCLUSAO  NUMBER       DEFAULT 1                                    NULL,
                                CDOPERINCLUSAO VARCHAR2(12) DEFAULT ''1''                                NULL,
                                NRORGULTATU    NUMBER       DEFAULT 1                                    NULL,
                                CDOPERULTATU   VARCHAR2(12) DEFAULT ''1'')';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL MODIFY CDFILIAL VARCHAR2(30) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL MODIFY NRLANCTONF VARCHAR2(10) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD CONSTRAINT PK_INTG_NOTAFISCAL PRIMARY KEY (CDFILIAL, NRLANCTONF)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD IDARQXMLNFE VARCHAR2(01) DEFAULT ''N'' NOT NULL
                               CONSTRAINT CKC_INTG_NOTAFISCALIDARQXMLNFE CHECK (IDARQXMLNFE IN (''S'', ''N''))';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD DSNMARQUXMLIMP VARCHAR2(150) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD IDSTATUS VARCHAR2(1) NULL
                               CONSTRAINT CKC_INTG_1013418 CHECK (IDSTATUS IS NULL OR (IDSTATUS IN (''P'',''A'',''E'',''C'',''V'',''G'',''R'',''L'',''D'',''I'',''U'')))';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD CDTIPOOPER VARCHAR2(2)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD CDVERSAOXML VARCHAR2(10)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD IDSTATUSNFE VARCHAR2(1) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD CDMODDOCFISC VARCHAR2(2) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD IDORIGDESTNF VARCHAR2(1) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'DELETE FROM INTG_NOTAFISCAL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL DROP CONSTRAINT PK_INTG_NOTAFISCAL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'DROP INDEX PK_INTG_NOTAFISCAL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD NRACESSONFE VARCHAR2(50) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD CONSTRAINT PK_INTG_NOTAFISCAL PRIMARY KEY (NRACESSONFE)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE INDEX INTG_NOTAFISCAL_01 ON INTG_NOTAFISCAL (CDFILIAL ASC, CDFORNECED ASC, DTEMISSAO ASC, IDSTATUSNFE ASC)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL MODIFY CDFILIAL VARCHAR2(30) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL MODIFY NRLANCTONF VARCHAR2(10) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL MODIFY DTEMISSAO DATE';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;
         
      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL MODIFY DTENTRSAID DATE';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL MODIFY DTLANCAMENNF DATE';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL MODIFY VRPRODUTOS FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL MODIFY VRNOTAFISC FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD DTHRPROTOCOLNFE DATE NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD IDTPAMBNFE VARCHAR2(1) DEFAULT ''0'' NOT NULL
                               CONSTRAINT CKC_IDTPAMBNFE_INTGNF CHECK (IDTPAMBNFE IN (''0'',''1'',''2''))';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD NRPROTOCOLONFE VARCHAR2(15) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD DSOBSSTATUSNFE VARCHAR2(1000) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD DTUTILIZAXML DATE NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE INDEX INTG_NOTAFISCAL_02 ON INTG_NOTAFISCAL (CDFORNECED ASC, CDSERIEENTR ASC, NRNOTAFISC ASC)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE INDEX INTG_NOTAFISCAL_03 ON INTG_NOTAFISCAL (NRACESSONFE ASC)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD DTIMPORTACAOXML DATE NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD DSNOMEARQUXML VARCHAR2(150) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD IDTIPOEMISNFE VARCHAR2(1) DEFAULT ''0'' NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL DROP CONSTRAINT CKC_IDTIPOEMISNFE_INTGNF';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD CONSTRAINT CKC_IDTIPOEMISNFE_INTGNF CHECK (IDTIPOEMISNFE IN (''0'',''1'',''2'',''3'',''4'',''5'',''6'',''7'',''8'',''9''))';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD NRINSJUREMPR VARCHAR2(20) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD IDDOCFISCELE VARCHAR2(1)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL
          ADD CONSTRAINT CKC_IDDOCFISCELE CHECK (IDDOCFISCELE IS NULL OR (IDDOCFISCELE IN (''0'',''1'')))';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD NRINSJURTRANXML VARCHAR2(20)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD NRPLACAVEICXML VARCHAR2(07)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD SGUFVEICXML VARCHAR2(02)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;
          
      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD IDPGTOFRETEXML VARCHAR2(01)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD DSQTDEVOLUXML VARCHAR2(10)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD DSESPECVOLUXML VARCHAR2(10)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD DSMARCAVOLUXML VARCHAR2(120)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD DSNUMEVOLUXML VARCHAR2(15)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD VRPBRUTOVOLUXML FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_NOTAFISCAL ADD VRPLIQUVOLUXML FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE TABLE INTG_INCONSISTENCIA
                            (
                               NRACESSONFE     VARCHAR2(44)    not null,
                               NRSEQINCONS     VARCHAR2(5)     not null,
                               CDCONSISTXML    VARCHAR2(3)     not null,
                               DSINCONSIS      VARCHAR2(300)   not null,
                                NRORG          NUMBER       DEFAULT SYS_CONTEXT(''nrorg_ctx'',''nrorg'') NOT NULL,
                                IDATIVO        VARCHAR2(1)  DEFAULT ''S''                                NOT NULL
                                   CONSTRAINT CKC_IDATIVO_INTG_INCONSISTENCIA CHECK (IDATIVO IN (''S'',''N'')),
                                DTINCLUSAO     DATE                                                      NULL,
                                DTULTATU       DATE                                                      NULL,
                                NRORGINCLUSAO  NUMBER       DEFAULT 1                                    NULL,
                                CDOPERINCLUSAO VARCHAR2(12) DEFAULT ''1''                                NULL,
                                NRORGULTATU    NUMBER       DEFAULT 1                                    NULL,
                                CDOPERULTATU   VARCHAR2(12) DEFAULT ''1''
                               CONSTRAINT PK_INTG_INCONSISTENCIA PRIMARY KEY (NRACESSONFE, NRSEQINCONS))';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_INCONSISTENCIA
                               ADD CONSTRAINT FKEST02253INTG_INCONS FOREIGN KEY  (NRACESSONFE)
                                  REFERENCES INTG_NOTAFISCAL (NRACESSONFE)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE INDEX FIS00492_FK ON INTG_INCONSISTENCIA (NRACESSONFE ASC)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO MODIFY CDFILIAL VARCHAR2(30) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO MODIFY NRLANCTONF VARCHAR2(10) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO MODIFY NRSEQITPROD VARCHAR2(4) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO
                               ADD CONSTRAINT FKEST00419INTG_NOT FOREIGN KEY  (CDFILIAL, NRLANCTONF)
                                  REFERENCES INTG_NOTAFISCAL (CDFILIAL, NRLANCTONF)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO ADD CONSTRAINT PK_INTG_ITEMPRODUT PRIMARY KEY (CDFILIAL, NRLANCTONF, NRSEQITPROD)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS MODIFY CDFILIAL VARCHAR2(30) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS MODIFY NRLANCTONF VARCHAR2(10) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS MODIFY NRSEQIMPOIT VARCHAR2(4) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS MODIFY CDIMPOSTOIT VARCHAR2(2) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS MODIFY NRITPROIMPOS VARCHAR2(1) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS
                               ADD CONSTRAINT FKEST00420INTG_ITE FOREIGN KEY  (CDFILIAL, NRLANCTONF, NRSEQIMPOIT)
                                  REFERENCES INTG_ITEMPRODUTO (CDFILIAL, NRLANCTONF, NRSEQITPROD)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS ADD CONSTRAINT PK_INTG_TRABITPROI PRIMARY KEY (CDFILIAL, NRLANCTONF, NRSEQIMPOIT, CDIMPOSTOIT, NRITPROIMPOS)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMENCARGO MODIFY CDFILIAL VARCHAR2(30) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMENCARGO MODIFY NRLANCTONF VARCHAR2(10) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMENCARGO MODIFY CDENCARGO VARCHAR2(2) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMENCARGO
                               ADD CONSTRAINT FKEST00421INTG_NOT FOREIGN KEY  (CDFILIAL, NRLANCTONF)
                                  REFERENCES INTG_NOTAFISCAL (CDFILIAL, NRLANCTONF)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMENCARGO ADD CONSTRAINT PK_INTG_ITEMENCARG PRIMARY KEY (CDFILIAL, NRLANCTONF, CDENCARGO)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_CONTAPAGAR MODIFY CDFILIAL VARCHAR2(30) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_CONTAPAGAR MODIFY NRLANCTONF VARCHAR2(10) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_CONTAPAGAR MODIFY NRSEQVENPAG VARCHAR2(2) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_CONTAPAGAR MODIFY NRPARCELAPAG VARCHAR2(2) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_CONTAPAGAR
                               ADD CONSTRAINT FKEST00422INTG_NOT FOREIGN KEY  (CDFILIAL, NRLANCTONF)
                                  REFERENCES INTG_NOTAFISCAL (CDFILIAL, NRLANCTONF)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_CONTAPAGAR ADD CONSTRAINT PK_INTG_CONTAPAGAR PRIMARY KEY (CDFILIAL, NRLANCTONF, NRSEQVENPAG, NRPARCELAPAG)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS DROP CONSTRAINT FKEST00420INTG_ITE';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS DROP CONSTRAINT PK_INTG_TRABITPROI';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'DROP INDEX PK_INTG_TRABITPROI';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_CONTAPAGAR DROP CONSTRAINT FKEST00422INTG_NOT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_CONTAPAGAR DROP CONSTRAINT PK_INTG_CONTAPAGAR';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'DROP INDEX PK_INTG_CONTAPAGAR';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMENCARGO DROP CONSTRAINT FKEST00421INTG_NOT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMENCARGO DROP CONSTRAINT PK_INTG_ITEMENCARG';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'DROP INDEX PK_INTG_ITEMENCARG';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO DROP CONSTRAINT FKEST00419INTG_NOT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO DROP CONSTRAINT PK_INTG_ITEMPRODUT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'DROP INDEX PK_INTG_ITEMPRODUT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO ADD NMPRODUTO VARCHAR2(50) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO ADD SGUNIDADE VARCHAR2(10) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO ADD CDINFADPROD VARCHAR2(30) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'DELETE FROM INTG_ITEMPRODUTO';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO ADD NRACESSONFE VARCHAR2(50) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE INDEX EST00419_FK ON INTG_ITEMPRODUTO (NRACESSONFE ASC)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO
                               ADD CONSTRAINT FKEST00419INTG_NOT FOREIGN KEY  (NRACESSONFE)
                                  REFERENCES INTG_NOTAFISCAL (NRACESSONFE)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO ADD CONSTRAINT PK_INTG_ITEMPRODUTO PRIMARY KEY (NRACESSONFE, NRSEQITPROD)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO MODIFY CDFILIAL VARCHAR2(30) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO MODIFY NRLANCTONF VARCHAR2(10) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'DELETE FROM INTG_TRABITPROIMPOS';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;
         
      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS ADD NRACESSONFE VARCHAR2(50) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE INDEX EST00420_FK ON INTG_TRABITPROIMPOS (NRACESSONFE ASC, NRSEQIMPOIT ASC)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS
                               ADD CONSTRAINT FKEST00420INTG_ITE FOREIGN KEY  (NRACESSONFE, NRSEQIMPOIT)
                                  REFERENCES INTG_ITEMPRODUTO (NRACESSONFE, NRSEQITPROD)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS ADD CONSTRAINT PK_INTG_TRABITPROIMPOS PRIMARY KEY (NRACESSONFE, NRSEQIMPOIT, CDIMPOSTOIT, NRITPROIMPOS)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS MODIFY CDFILIAL VARCHAR2(30) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS MODIFY NRLANCTONF VARCHAR2(10) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'DELETE FROM INTG_ITEMENCARGO';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMENCARGO ADD NRACESSONFE VARCHAR2(50) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE INDEX EST00421_FK ON INTG_ITEMENCARGO (NRACESSONFE ASC)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMENCARGO
                               ADD CONSTRAINT FKEST00421INTG_NOT FOREIGN KEY  (NRACESSONFE)
                                  REFERENCES INTG_NOTAFISCAL (NRACESSONFE)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMENCARGO ADD CONSTRAINT PK_INTG_ITEMENCARGO PRIMARY KEY (NRACESSONFE, CDENCARGO)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMENCARGO MODIFY CDFILIAL VARCHAR2(30) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMENCARGO MODIFY NRLANCTONF VARCHAR2(10) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'DELETE FROM INTG_CONTAPAGAR';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_CONTAPAGAR ADD NRACESSONFE VARCHAR2(50) NOT NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE INDEX EST00422_FK ON INTG_CONTAPAGAR (NRACESSONFE ASC)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_CONTAPAGAR
                               ADD CONSTRAINT FKEST00422INTG_NOT FOREIGN KEY  (NRACESSONFE)
                                  REFERENCES INTG_NOTAFISCAL (NRACESSONFE)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_CONTAPAGAR ADD CONSTRAINT PK_INTG_CONTAPAGAR PRIMARY KEY (NRACESSONFE, NRSEQVENPAG, NRPARCELAPAG)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_CONTAPAGAR MODIFY CDFILIAL VARCHAR2(30) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_CONTAPAGAR MODIFY NRLANCTONF VARCHAR2(10) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO MODIFY DTPROGENTAF DATE';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO MODIFY QTITEMPROD FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO MODIFY VRUNITITEM FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO MODIFY VRDESCITEM FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO MODIFY VRTOTAITEM FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO MODIFY VRCONTITEM FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO MODIFY VRDESPERITEM FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_CONTAPAGAR MODIFY DTORIGVENPAG DATE';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_CONTAPAGAR MODIFY VRORIGPAG FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS MODIFY VRCONTITIMP FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS MODIFY VRPERREDBCIT FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS MODIFY VRBASECALCIT FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS MODIFY VRALIQITEM FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS MODIFY VRIMPOSTOIT FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMENCARGO MODIFY VRITEMENCA FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO ADD CDFISOPEITEM VARCHAR2(11) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO ADD CDSITUTRIBPR VARCHAR2(3) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS ADD IDMODBCITNFE VARCHAR2(1) NULL
                               CONSTRAINT CKC_IDMODBCITNFE_INTG CHECK (IDMODBCITNFE IS NULL OR (IDMODBCITNFE IN (''0'',''1'',''2'',''3'')))';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS ADD IDMODBCSTITNFE VARCHAR2(1) NULL
                               CONSTRAINT CKC_IDMODBCSTITNFE_INTG CHECK (IDMODBCSTITNFE IS NULL OR (IDMODBCSTITNFE IN (''0'',''1'',''2'',''3'',''4'',''5'')))';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO ADD IDORIGEMPROD VARCHAR2(01) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_ITEMPRODUTO ADD CDCLASFISC VARCHAR2(10) NULL';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE TABLE RELACNFECTE
                            (
                               NRACESSONFE 	VARCHAR2(50),
                               NRACESSONFECTE 	VARCHAR2(50),
                               NRORG          NUMBER       DEFAULT SYS_CONTEXT(''nrorg_ctx'',''nrorg'') NOT NULL,
                               IDATIVO        VARCHAR2(1)  DEFAULT ''S''                                NOT NULL
                                  CONSTRAINT CKC_IDATIVO_RELACNFECTE CHECK (IDATIVO IN (''S'',''N'')),
                               DTINCLUSAO     DATE                                                      NULL,
                               DTULTATU       DATE                                                      NULL,
                               NRORGINCLUSAO  NUMBER       DEFAULT 1                                    NULL,
                               CDOPERINCLUSAO VARCHAR2(12) DEFAULT ''1''                                NULL,
                               NRORGULTATU    NUMBER       DEFAULT 1                                    NULL,
                               CDOPERULTATU   VARCHAR2(12) DEFAULT ''1'')';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS ADD VRADICALIQFECP FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'ALTER TABLE INTG_TRABITPROIMPOS ADD VRADICFECP FLOAT';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE TABLE  INTG_ITEMAF   (
                            NRACESSONFE 	VARCHAR2(44),
                            NRSEQITPROD 	VARCHAR2(44),
                            NRAUTOFORNE 	VARCHAR2(44),
                            CDPRODUTOXML	VARCHAR2(44), 
                            QTITEMPRODXML 	FLOAT,
                            QTPRODBAIXADA	 FLOAT,
                            NRORG          NUMBER       DEFAULT SYS_CONTEXT(''nrorg_ctx'',''nrorg'') NOT NULL,
                            IDATIVO        VARCHAR2(1)  DEFAULT ''S''                                NOT NULL
                               CONSTRAINT CKC_IDATIVO_INTG_ITEMAF CHECK (IDATIVO IN (''S'',''N'')),
                            DTINCLUSAO     DATE                                                      NULL,
                            DTULTATU       DATE                                                      NULL,
                            NRORGINCLUSAO  NUMBER       DEFAULT 1                                    NULL,
                            CDOPERINCLUSAO VARCHAR2(12) DEFAULT ''1''                                NULL,
                            NRORGULTATU    NUMBER       DEFAULT 1                                    NULL,
                            CDOPERULTATU   VARCHAR2(12) DEFAULT ''1'',
                            CONSTRAINT PK_INTG_ITEMAF PRIMARY KEY (NRACESSONFE,NRSEQITPROD, NRAUTOFORNE))';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE INDEX FK_FIS00722 ON INTG_ITEMAF (NRACESSONFE ASC)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

      BEGIN
         EXECUTE IMMEDIATE 'CREATE INDEX FK_FIS00723 ON INTG_ITEMAF (NRAUTOFORNE ASC)';
      EXCEPTION
         WHEN OTHERS THEN
            V_ERROR := SUBSTR(SQLERRM, 1, 200);
      END;

   END IF;
END;