CREATE TABLE CTB_TEMP_CREDPRES (
   CDFILIAL 		VARCHAR2(4) 	NOT NULL ,
   VRTOTENTRADAS 	FLOAT(126),
   VRTOTSAIDAS 		FLOAT(126),
   VRCREDPRES 		FLOAT(126),
   VRGLP 			FLOAT(126),
   VRSAIDCONTAB 		FLOAT(126),
   CDCONTCTBLCRED 	VARCHAR2(20),
   CDCONTCTBLDEB  	VARCHAR2(20),
   NRORG                       	NUMBER 		DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO                    	VARCHAR2(1)     	DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_CTBTEMPCP 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'
)
/

CREATE TABLE ESTORNO (
    CDINSCESTA        	VARCHAR2(20) 	NOT NULL,
    SGESTADO          		VARCHAR2(02) 	NOT NULL,
    DSESTORNOCRED     	VARCHAR2(200),
    DSESTORNODEBI     	VARCHAR2(200),
    VRPERCENTEST      	NUMBER,
    VRPERCENTGAS      	NUMBER,
    CDCONTCTBL        	VARCHAR2(20),
    CDCONTCTBOL       	VARCHAR2(20),
    CDGRUPOFISC       	VARCHAR2(03), 
   NRORG                       	NUMBER 		DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO                    	VARCHAR2(1)     	DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_ESTORNO 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',
    CONSTRAINT PK_ESTORNO PRIMARY KEY (CDINSCESTA, SGESTADO) 
)
/

ALTER TABLE CTB_TEMP_CREDPRES ADD NRNOTAFISC VARCHAR2(20) NULL
/

ALTER TABLE CTB_TEMP_CREDPRES ADD CDINSCESTA VARCHAR2(20) NULL
/

ALTER TABLE CTB_TEMP_CREDPRES ADD DSHISTORICO VARCHAR2(600) NULL