CREATE TABLE AJUSTEFECP  
(  
    CDEMPRESA           VARCHAR2(2)            NOT NULL,
    CDINSCESTA          VARCHAR2(16)           NOT NULL,
    CDIMPOSTO           VARCHAR2(2)            NOT NULL,
    IDSOMAFECP          VARCHAR2(1)            NULL
        CONSTRAINT CKC_IDSOMAFECP CHECK (IDSOMAFECP IN ('S','N')),
    TPAJUSTEFECP        VARCHAR2(3)            NULL
        CONSTRAINT CKC_TPAJUSTEFECP CHECK (TPAJUSTEFECP IN ('DDE','DE','OD','N')),
    CDAJUSTEDDUE        VARCHAR2(10)           NULL,
    CDAJUSTDEBESP       VARCHAR2(10)           NULL,
    CDAJUSTOUTDEB       VARCHAR2(10)           NULL,
    IDGERAREGC191       VARCHAR2(1)            NULL
        CONSTRAINT CKC_IDGERAREGC191 CHECK (IDGERAREGC191 IN ('S','N')),
    NRORG               NUMBER                 DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO 			VARCHAR2(1) 	DEFAULT 'S' NOT NULL,
		CONSTRAINT CKC_IDATIVO_AJUSTEFECP CHECK (IDATIVO IN ('S','N')),
    DTINCLUSAO          DATE                   NULL    ,
    DTULTATU            DATE                   NULL    ,
    NRORGINCLUSAO       NUMBER                 DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL  ,
    CDOPERINCLUSAO      VARCHAR2(12)           DEFAULT '1' NULL,
    NRORGULTATU         NUMBER                 DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL  ,
    CDOPERULTATU        VARCHAR2(12)           DEFAULT '1' NULL,
		CONSTRAINT PK_AJUSTEFECP PRIMARY KEY (CDEMPRESA, CDINSCESTA)
)
/

CREATE INDEX FIS00771_FK ON AJUSTEFECP (CDEMPRESA ASC, CDINSCESTA ASC, CDIMPOSTO ASC)
/

ALTER TABLE AJUSTEFECP
    ADD CONSTRAINT FKFIS00771INSCREST FOREIGN KEY  (CDEMPRESA, CDINSCESTA, CDIMPOSTO)
       REFERENCES INSCRESTAD (CDEMPRESA, CDINSCESTA, CDIMPOSTO)
/

ALTER TABLE PARAMESTSPED ADD TPAPURACAO VARCHAR2(1) DEFAULT '3' NOT NULL
   CONSTRAINT CKC_TPAPURACAO_PARAMESTSPED CHECK (TPAPURACAO  IN ('3','4','5','6','7','8'))
/

ALTER TABLE PARAMESTSPED ADD IDGERAJUST VARCHAR2(2) DEFAULT 'N' NOT NULL
   CONSTRAINT CKC_IDGERAJUST_PARAMESTSPED CHECK (IDGERAJUST IN ('S','N'))
/

ALTER TABLE PARAMESTSPED ADD IDESTABVAREJ VARCHAR2(2) DEFAULT 'N' NOT NULL
   CONSTRAINT CKC_IDESTABVAREJ_PARAMESTSPED CHECK (IDESTABVAREJ IN ('S','N'))
/

ALTER TABLE PARAMESTSPED ADD CDAJUSTEENTRTRIB VARCHAR2(10) NULL
/

ALTER TABLE PARAMESTSPED ADD DSAJUSTEENTRTRIB VARCHAR2(400) NULL
/

ALTER TABLE PARAMESTSPED ADD CDAJUSTESAIDTRIB VARCHAR2(10) NULL
/

ALTER TABLE PARAMESTSPED ADD DSAJUSTESAIDTRIB VARCHAR2(400) NULL
/

ALTER TABLE PARAMESTSPED ADD CDAJUSTEVRREST VARCHAR2(10) NULL
/

ALTER TABLE PARAMESTSPED ADD DSAJUSTEVRREST VARCHAR2(400) NULL
/

ALTER TABLE PARAMESTSPED ADD CDAJUSTEVRCOMPL VARCHAR2(10) NULL
/

ALTER TABLE PARAMESTSPED ADD DSAJUSTEVRCOMPL VARCHAR2(400) NULL
/

ALTER TABLE PARAMESTSPED ADD CDAJUSTEE220VRREST VARCHAR2(10) NULL
/

ALTER TABLE PARAMESTSPED ADD DSAJUSTEE220VRREST VARCHAR2(400) NULL
/

ALTER TABLE PARAMESTSPED ADD CDAJUSTEE220VRCOMP VARCHAR2(10) NULL
/

ALTER TABLE PARAMESTSPED ADD DSAJUSTEE220VRCOMP VARCHAR2(400) NULL
/

ALTER TABLE PARAMESTSPED ADD VRALIQINTERNA FLOAT NULL
/

ALTER TABLE ENTRADAREF ADD CDPRODESTOCOMP VARCHAR2(10) NULL
/

ALTER TABLE MAPAAPURESTADO ADD VRSTNFSAID FLOAT(126) NULL
/

ALTER TABLE MAPAAPURESTADO ADD VRSTNFENTR FLOAT(126) NULL
/

ALTER TABLE MAPAAPURESTADO ADD VRSTNFCOMP FLOAT(126) NULL
/

ALTER TABLE MAPAAPURESTADO ADD VRSTNFRESS FLOAT(126) NULL
/

ALTER TABLE AJUSTMAPAAPURSG ADD IDGERAUTO VARCHAR2(2) DEFAULT 'N' NOT NULL
   CONSTRAINT CKC_IDGERAUTO_AJUSTMAPAAPURSG CHECK (IDGERAUTO IN ('S','N'))
/

ALTER TABLE AJUSTMAPAAPURSG MODIFY DSAJUSTEAPURSG VARCHAR2(400)