CREATE TABLE GERAPAPARCIAL (
  NRGERAPAPARCIAL NUMBER(10) NOT NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  NRPLANPROD NUMBER(10) NOT NULL, 
  CDPRODACABADO VARCHAR2(10) NOT NULL, 
  IDCOOKCHILL VARCHAR2(1) DEFAULT 'N' NOT NULL, 
  IDFINALIZACAO VARCHAR2(1) DEFAULT 'M' NULL, 
  IDTPPRODCHILL VARCHAR2(30) DEFAULT 'NENHUM' NULL, 
  IDESTADO VARCHAR2(30) DEFAULT 'FINALIZACAO' NULL, 
  NRSEQPRODACABADO NUMBER(10) DEFAULT 1 NULL, 
  QTPRODUZIDO DOUBLE PRECISION NOT NULL, 
  CDCONTAINER VARCHAR2(5) NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NOT NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NOT NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NOT NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NOT NULL,
  CONSTRAINT PK_GERAPAPARCIAL PRIMARY KEY(NRGERAPAPARCIAL, NRORG)
)
/
ALTER TABLE GERAPAPARCIAL ADD CONSTRAINT CKC_IDATIVO_GERAPAPARCIAL CHECK (IDATIVO IN ('S','N'))
/
ALTER TABLE GERAPAPARCIAL ADD CONSTRAINT CKC_IDFINALIZACAO_GERAPAPARC CHECK (IDFINALIZACAO IN ('M','F'))
/
ALTER TABLE GERAPAPARCIAL ADD CONSTRAINT CKC_IDCOOKCHILL_GERAPAPARC CHECK (IDCOOKCHILL IN ('S','N'))
/
ALTER TABLE GERAPAPARCIAL ADD CONSTRAINT CKC_IDTPPRODCHILL_GERAPAPARC CHECK (IDTPPRODCHILL IN ('CONGELADO','RESFRIADO','NENHUM'))
/
ALTER TABLE GERAPAPARCIAL ADD CONSTRAINT CKC_IDESTADO_GERAPAPARC CHECK (IDESTADO IN ('PRODUCAO', 'FINALIZACAO'))
/
ALTER TABLE GERAPARCIAL
    ADD CONSTRAINT FKPLA00919PLANPRODACABADO FOREIGN KEY  (NRPLANPROD, CDPRODACABADO,IDCOOKCHILL,IDFINALIZACAO,IDTPPRODCHILL,IDESTADO, NRORG)
       REFERENCES PLANPRODACABADO (NRPLANPROD, CDPRODACABADO,IDCOOKCHILL,IDFINALIZACAO,IDTPPRODCHILL,IDESTADO, NRORG)
/
CREATE INDEX PLA00919_FK ON GERAPARCIAL (NRPLANPROD, CDPRODACABADO,IDCOOKCHILL,IDFINALIZACAO,IDTPPRODCHILL,IDESTADO, NRORG)
/
ALTER TABLE GERAPARCIAL
    ADD CONSTRAINT FKPLA00920CONTAINER FOREIGN KEY  (CDCONTAINER, NRORG)
       REFERENCES CONTAINER (CDCONTAINER, NRORG)
/
CREATE INDEX  PLA00920_FK ON GERAPARCIAL (CDCONTAINER, NRORG)
/