CREATE TABLE PRODCADENCI ( 
    NRPRODCADENCI 	NUMBER NOT NULL,
    NRORG 			NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx', 'nrorg') NOT NULL,
    CDFILIAL 		VARCHAR2(4) NOT NULL, 
    CDSERVFILI 		VARCHAR2(5) NOT NULL, 
    DTCARDAPIO 		DATE NOT NULL, 
    CDPRATO 		VARCHAR2(10) NOT NULL, 
    CDFILAUXPRAT 	VARCHAR2(4) NOT NULL, 
    QUANTIDADE 		FLOAT NOT NULL, 
    IDSTATUS 		VARCHAR2(1) DEFAULT 'P' NOT NULL    
        CONSTRAINT CKC_IDSTATUS_PRODCADENCI CHECK (IDSTATUS IN ('P','A', 'C', 'R')), 
    NRCOMENSAIS 	NUMBER NOT NULL, 
    INIPREPPLA 		FLOAT, 
    FIMPREPPLA 		FLOAT, 
    INIPREPREAL 	FLOAT, 
    FIMPREPREAL 	FLOAT,
	IDATIVO         VARCHAR2(1)     DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_PRODCADENCI 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',
    IDCONFIRMPLAN 	VARCHAR2(1) DEFAULT 'S' NOT NULL
        CONSTRAINT CKC_IDCONFIRMPLAN_PRODCADENCI CHECK (IDCONFIRMPLAN IN ('S','N')),
    IDBLOQPROD 		VARCHAR2(1) DEFAULT 'N' NOT NULL
        CONSTRAINT CKC_IDBLOQPROD_PRODCADENCI CHECK (IDBLOQPROD IN ('S','N')),
		CONSTRAINT PK_PRODCADENCI PRIMARY KEY (NRPRODCADENCI)
)
/
CREATE INDEX PRODCADENCI_INDEX ON PRODCADENCI (CDFILIAL, CDSERVFILI, DTCARDAPIO)
/

CREATE TABLE EQPRODCADENCI ( 
    NREQPRODCADENCI 	NUMBER NOT NULL,
    NRORG 				NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx', 'nrorg') NOT NULL,
    NRPRODCADENCI 		NUMBER NOT NULL,
    NREQUIPAMENTO 		NUMBER NOT NULL, 
    QTDEQUIPUTIL 		NUMBER NOT NULL,
    TEMPOINI 			FLOAT NOT NULL,
    TEMPOFIN 			FLOAT NOT NULL,
	IDATIVO           	VARCHAR2(1)     DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_EQPRODCADENCI 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_EQPRODCADENCI PRIMARY KEY (NREQPRODCADENCI, NRPRODCADENCI )
)
/ 
CREATE INDEX PLA01256_FK ON EQPRODCADENCI (NRPRODCADENCI ASC)
/
ALTER TABLE EQPRODCADENCI ADD CONSTRAINT FKPLA01256EQPRODCADENCI FOREIGN KEY (NRPRODCADENCI) REFERENCES PRODCADENCI (NRPRODCADENCI)
/
CREATE INDEX PLA01257_FK ON EQPRODCADENCI (NREQUIPAMENTO ASC)
/
ALTER TABLE EQPRODCADENCI ADD CONSTRAINT FKPLA01257EQPRODCADENCI FOREIGN KEY (NREQUIPAMENTO) REFERENCES EQUIPAMCOZ (NREQUIPAMCOZ)
/