CREATE TABLE FCT_RATEIOITFATURACONT ( 
	NRRATEIOITEMFAT  	NUMBER      	NOT NULL,
	NRITFATURACONT   	NUMBER      	NOT NULL,
	NRFATURACONT     	NUMBER      	NOT NULL,
	NRSEQCONTRATO    	NUMBER      	NOT NULL,
	NRITEMOCONTRATO  	NUMBER      	NOT NULL,
	NRESTRUTURAM     	NUMBER      	NOT NULL, 
	CDCENTCUST       	VARCHAR2(4) 	NOT NULL,
	VRPERCENTRATEIO  	NUMBER,
	VRRATEADO        	NUMBER,
    NRORG 				NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
	IDATIVO 			VARCHAR2(1) 	DEFAULT 'S' NOT NULL,
		CONSTRAINT CKC_IDATIVO_FCT_RATITFATCONT 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',
	IDSITUVENCRATEIO 	CHAR(1),
	NRAPURACAO       	NUMBER
)
/
ALTER TABLE FCT_RATEIOITFATURACONT ADD CONSTRAINT PK_RATEIOITFATURACONT PRIMARY KEY(NRRATEIOITEMFAT)
/
CREATE INDEX SM00277_FK ON FCT_RATEIOITFATURACONT (NRITFATURACONT ASC)
/
ALTER TABLE FCT_RATEIOITFATURACONT ADD 
	CONSTRAINT FKSM00277ITFATURACONT FOREIGN KEY (NRITFATURACONT)
		REFERENCES FCT_ITFATURACONT(NRITFATURACONT) ON DELETE CASCADE
/
CREATE INDEX SM00278_FK ON FCT_RATEIOITFATURACONT (NRFATURACONT ASC)
/
ALTER TABLE FCT_RATEIOITFATURACONT ADD 
	CONSTRAINT FKSM00278FATURACONT FOREIGN KEY (NRFATURACONT)
		REFERENCES FCT_FATURACONT(NRFATURACONT) ON DELETE CASCADE
/
CREATE INDEX SM00279_FK ON FCT_RATEIOITFATURACONT (NRSEQCONTRATO ASC)
/
ALTER TABLE FCT_RATEIOITFATURACONT ADD 
	CONSTRAINT FKSM00279CONTRATO FOREIGN KEY (NRSEQCONTRATO)
		REFERENCES FCT_CONTRATO(NRSEQCONTRATO) ON DELETE CASCADE
/
CREATE INDEX SM00280_FK ON FCT_RATEIOITFATURACONT (NRITEMOCONTRATO ASC)
/
ALTER TABLE FCT_RATEIOITFATURACONT ADD 
	CONSTRAINT FKSM00280ITEMCONTRATO FOREIGN KEY (NRITEMOCONTRATO)
		REFERENCES FCT_ITEMCONTRATO(NRITEMOCONTRATO) ON DELETE CASCADE
/
CREATE INDEX SM00281_FK ON FCT_RATEIOITFATURACONT (NRESTRUTURAM ASC)
/
ALTER TABLE FCT_RATEIOITFATURACONT ADD 
	CONSTRAINT FKSM00281ESTRUTURAM FOREIGN KEY (NRESTRUTURAM)
		REFERENCES ESTRUTURAM(NRESTRUTURAM) ON DELETE CASCADE
/
CREATE INDEX SM00282_FK ON FCT_RATEIOITFATURACONT (CDCENTCUST ASC)
/
ALTER TABLE FCT_RATEIOITFATURACONT ADD 
	CONSTRAINT FKSM00282CENTCUST FOREIGN KEY (CDCENTCUST)
		REFERENCES CENTCUST(CDCENTCUST) ON DELETE CASCADE
/
CREATE INDEX SM00283_FK ON FCT_RATEIOITFATURACONT (NRAPURACAO ASC)
/
ALTER TABLE FCT_RATEIOITFATURACONT ADD 
	CONSTRAINT FKSM00283APURACAO FOREIGN KEY (NRAPURACAO) 
		REFERENCES FCT_APURACAO(NRAPURACAO)
/
ALTER TABLE FCT_RATEIOITFATURACONT ADD 
	CONSTRAINT CKC_IDSIT_RATEIOITFATURACONT CHECK(IDSITUVENCRATEIO IN ('1', '2', '3', '4', '5', '6'))
/
ALTER TABLE FCT_FATURACONT DROP CONSTRAINT CKC_IDSITUACAO_FCT_FATURACONT
/
ALTER TABLE FCT_FATURACONT ADD CONSTRAINT CKC_IDSITUACAO_FCT_FATURACONT CHECK(IDSITUACAO IN ('1', '2', '3', '4', '5', '6'))
/
ALTER TABLE FCT_ITFATURACONT DROP CONSTRAINT CKC_IDSITUACAO_FCT_ITFATCONT
/
ALTER TABLE FCT_ITFATURACONT ADD CONSTRAINT CKC_IDSITUACAO_FCT_ITFATCONT CHECK(IDSITUACAO IN ('1', '2', '3', '4', '5', '6'))
/
ALTER TABLE FCT_APURACAO ADD DSTIPOAPURACAO VARCHAR2(5) DEFAULT 'APU' NOT NULL 
/
ALTER TABLE FCT_APURACAO ADD CONSTRAINT CKC_DSTPAPURACAO_FCT_APURACAO CHECK(DSTIPOAPURACAO IN ('APU', 'ITEM', 'RAT')) 