CREATE TABLE CUSTOPACOZ(
	NRCUSTOPACOZ   	  NUMBER 		  NOT NULL, 
	DTVIGENCIA     	  DATE 			  NOT NULL, 
	CDCENTRAL      	  VARCHAR2(4)     NOT NULL, 
	CDFILIAL 	   	  VARCHAR2(4) 	  NOT NULL, 
	CDPRODUTO 	   	  VARCHAR2(10) 	  NOT NULL, 
	VRUNIT 		   	  FLOAT(126) 	  NOT NULL, 
	NRORG             NUMBER 	      DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') 		NOT NULL,
    IDATIVO           VARCHAR2(1)     DEFAULT 'S'					NOT NULL,
    DTINCLUSAO        DATE            DEFAULT SYSDATE,
    DTULTATU          DATE            DEFAULT SYSDATE,
    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'
)
/

ALTER TABLE CUSTOPACOZ ADD CONSTRAINT PK_CUSTOPACOZ PRIMARY KEY (NRCUSTOPACOZ)
/

ALTER TABLE CUSTOPACOZ ADD CONSTRAINT CKC_IDATIVO_CUSTOPACOZ CHECK (IDATIVO IN ('S', 'N'))
/

ALTER TABLE CUSTOPACOZ ADD CONSTRAINT FKCOZ00004FILIAL FOREIGN KEY(CDFILIAL) 
	REFERENCES FILIAL(CDFILIAL)
/

CREATE INDEX FKCOZ00004_FK ON CUSTOPACOZ(CDFILIAL ASC)
/

ALTER TABLE CUSTOPACOZ ADD CONSTRAINT FKCOZ00005FILIAL FOREIGN KEY(CDCENTRAL) 
	REFERENCES FILIAL(CDFILIAL)
/

CREATE INDEX FKCOZ00005_FK ON CUSTOPACOZ(CDCENTRAL ASC)
/

ALTER TABLE CUSTOPACOZ ADD
	CONSTRAINT FKCOZ00006PRODUTO FOREIGN KEY(CDPRODUTO) 
		REFERENCES PRODUTO(CDPRODUTO)
/

CREATE INDEX FKCOZ00006_FK ON CUSTOPACOZ(CDPRODUTO ASC)
/