CREATE TABLE SERVICOGEN (
  NRSERVICOGEN NUMBER(10) NOT NULL, 
  SGUNIDADE VARCHAR2(10) NOT NULL, 
  CDPRODUTO VARCHAR2(10) NOT NULL, 
  DSSERVICOGEN VARCHAR2(50) NOT NULL, 
  DSSERVICOGENING VARCHAR2(50) DEFAULT NULL NULL, 
  DSSERVICOGENESP VARCHAR2(50) DEFAULT NULL NULL, 
  IDSERVICO VARCHAR2(1) NOT NULL, 
  VRPESOSE DOUBLE PRECISION NOT NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  DTINCLUSAO DATE NOT NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NOT NULL, 
  DTULTATU DATE NOT NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NOT NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NOT NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL,
  CONSTRAINT PK_SERVICOGEN PRIMARY KEY(NRSERVICOGEN, NRORG)
)
/
ALTER TABLE SERVICOGEN ADD CONSTRAINT FKCOC00316UNIDMEDIDA FOREIGN KEY (SGUNIDADE, NRORG) REFERENCES UNIDMEDIDA (SGUNIDADE, NRORG)
/
ALTER TABLE SERVICOGEN ADD CONSTRAINT CKC_IDSERVICO_SERVICOGEN CHECK (IDSERVICO in ('1','2','3','4','5'))
/
ALTER TABLE SERVICOGEN ADD CONSTRAINT CKC_IDATIVO_SERVICOGEN CHECK (IDATIVO in ('S','N'))
/
create index COC00316_FK on SERVICOGEN (SGUNIDADE asc, NRORG)
/
CREATE TABLE SERVICOCIAFILI (
  CDFILIAL VARCHAR2(4) NOT NULL, 
  CDCIA VARCHAR2(4) NOT NULL, 
  NRSERVICOCIAFILI NUMBER(10) NOT NULL, 
  NRSERVICOGEN NUMBER(10) NOT NULL, 
  CDPRODUTO VARCHAR2(10) NOT NULL, 
  CDSETOR VARCHAR2(4) DEFAULT NULL NULL, 
  IDSITSERVICO VARCHAR2(1) DEFAULT '1' NOT NULL, 
  IDTPPRECO VARCHAR2(1) DEFAULT '1' NOT NULL, 
  TXCOMENTASE VARCHAR2(500) DEFAULT NULL NULL, 
  IDTIPMANUAL VARCHAR2(1) DEFAULT '1' NOT NULL, 
  IDSERVESP VARCHAR2(1) DEFAULT '1' NOT NULL, 
  IDFATSE VARCHAR2(1) DEFAULT '1' NOT NULL, 
  DSSERVICOCIAFILI VARCHAR2(100) DEFAULT NULL NULL, 
  DSSERVICOCIAFILIING VARCHAR2(100) DEFAULT NULL NULL, 
  DSSERVICOCIAFILIESP VARCHAR2(100) DEFAULT NULL NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  DTINCLUSAO DATE NOT NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NOT NULL, 
  DTULTATU DATE NOT NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NOT NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NOT NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL,
  CONSTRAINT PK_SERVICOCIAFILI PRIMARY KEY(CDFILIAL, CDCIA, NRSERVICOCIAFILI, NRORG)
)
/
ALTER TABLE SERVICOCIAFILI ADD CONSTRAINT FKCOC00317SERVICOGEN FOREIGN KEY (NRSERVICOGEN, NRORG) REFERENCES SERVICOGEN (NRSERVICOGEN, NRORG)
/
ALTER TABLE SERVICOCIAFILI ADD CONSTRAINT FKCOC00318SETORFILIAL FOREIGN KEY (CDSETOR, CDFILIAL, NRORG) REFERENCES SETORFILIAL (CDSETOR, CDFILIAL, NRORG)
/
ALTER TABLE SERVICOCIAFILI ADD CONSTRAINT FKCOC00319CIAFILI FOREIGN KEY (CDFILIAL, CDCIA, NRORG) REFERENCES CIAFILI (CDFILIAL, CDCIA, NRORG)
/
ALTER TABLE SERVICOCIAFILI ADD CONSTRAINT CKC_IDSERVESP CHECK (IDSERVESP in ('1','2'))
/
ALTER TABLE SERVICOCIAFILI ADD CONSTRAINT CKC_IDSITSERVICO CHECK (IDSITSERVICO in ('1','2'))
/
ALTER TABLE SERVICOCIAFILI ADD CONSTRAINT CKC_IDTPPRECO CHECK (IDTPPRECO in ('1','2'))
/
ALTER TABLE SERVICOCIAFILI ADD CONSTRAINT CKC_IDFATSE CHECK (IDFATSE in ('1','2'))
/
ALTER TABLE SERVICOCIAFILI ADD CONSTRAINT CKC_IDATIVO_SERVICOCIAFILI CHECK (IDATIVO in ('S','N'))
/
ALTER TABLE SERVICOCIAFILI ADD CONSTRAINT CKC_IDTIPMANUAL CHECK (IDTIPMANUAL in ('1','2'))
/
create index COC00317_FK on SERVICOCIAFILI (NRSERVICOGEN asc, NRORG ASC)
/
create index COC00318_FK on SERVICOCIAFILI (CDSETOR, CDFILIAL, NRORG)
/
CREATE TABLE SERVCICLO (
  CDFILIAL VARCHAR2(4) NOT NULL, 
  CDCIA VARCHAR2(4) NOT NULL, 
  NRSERVICOCIAFILI NUMBER(10) NOT NULL, 
  CDCLASSE VARCHAR2(4) NOT NULL, 
  CDCICLO VARCHAR2(4) NOT NULL, 
  VRPESOSE DOUBLE PRECISION DEFAULT NULL NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  DTINCLUSAO DATE NOT NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NOT NULL, 
  DTULTATU DATE NOT NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NOT NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NOT NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  CDSERVICO VARCHAR2(10) NOT NULL, 
  CDARVSERV VARCHAR2(20) NOT NULL,
  CONSTRAINT PK_SERVCICLO PRIMARY KEY(CDFILIAL, CDCIA, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, NRORG)
)
/
ALTER TABLE SERVCICLO ADD CONSTRAINT FKCOC00323SERVICOCIAFILI FOREIGN KEY (CDFILIAL, CDCIA, NRSERVICOCIAFILI, NRORG) REFERENCES SERVICOCIAFILI (CDFILIAL, CDCIA, NRSERVICOCIAFILI, NRORG)
/
ALTER TABLE SERVCICLO ADD CONSTRAINT FKCOC00324CICLOCIA FOREIGN KEY (CDFILIAL, CDCIA, CDCICLO, NRORG) REFERENCES CICLOCIA (CDFILIAL, CDCIA, CDCICLO, NRORG)
/
ALTER TABLE SERVCICLO ADD CONSTRAINT FKCOC00325CLASSECIA FOREIGN KEY (CDFILIAL, CDCIA, CDCLASSE, NRORG) REFERENCES CLASSECIA (CDFILIAL, CDCIA, CDCLASSE, NRORG)
/
ALTER TABLE SERVCICLO ADD CONSTRAINT CKC_IDATIVO_SERVCICLO CHECK (IDATIVO in ('S','N'))
/
create index COC00321_FK on SERVCICLO (CDCICLO asc, NRORG asc)
/
create index COC00322_FK on SERVCICLO (CDCLASSE asc, NRORG asc)
/
CREATE TABLE PRECOSECIAM (
  CDFILIAL VARCHAR2(4) NOT NULL, 
  CDCIA VARCHAR2(4) NOT NULL, 
  NRTABPRECO VARCHAR2(3) NOT NULL, 
  NRSERVICOCIAFILI NUMBER(10) NOT NULL, 
  CDCLASSE VARCHAR2(4) NOT NULL, 
  CDCICLO VARCHAR2(4) NOT NULL, 
  NRSEQPRECO NUMBER(10) NOT NULL, 
  VRPRESERV DOUBLE PRECISION NOT NULL, 
  VRPRESERVD DOUBLE PRECISION NOT NULL, 
  DTINIVIGSE DATE NOT NULL, 
  DTFIMVIGSE DATE NOT NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  DTINCLUSAO DATE NOT NULL, 
  DTULTATU DATE NOT 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, 
  CDSERVICO VARCHAR2(10) DEFAULT NULL NULL,
  CONSTRAINT PK_PRECOSECIAM PRIMARY KEY(CDFILIAL, CDCIA, NRTABPRECO, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, NRORG)
)
/
ALTER TABLE PRECOSECIAM ADD CONSTRAINT FKCOC00327SERVCICLO FOREIGN KEY (CDFILIAL, CDCIA, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, NRORG) REFERENCES SERVCICLO (CDFILIAL, CDCIA, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, NRORG)
/
ALTER TABLE PRECOSECIAM ADD CONSTRAINT FKCOC00336TABPRECOSE FOREIGN KEY (CDFILIAL, CDCIA, NRTABPRECO, NRORG) REFERENCES TABPRECOSE (CDFILIAL, CDCIA, NRTABPRECO, NRORG)
/
ALTER TABLE PRECOSECIAM ADD CONSTRAINT CKC_IDATIVO_PRECOSECIAM CHECK (IDATIVO in ('S','N'))
/
create index COC00326_FK on PRECOSECIAM (NRTABPRECO asc, NRORG asc)
/
CREATE TABLE PROPRECOSEM (
  CDFILIAL VARCHAR2(4) NOT NULL, 
  CDCIA VARCHAR2(4) NOT NULL, 
  NRTABPRECO VARCHAR2(3) NOT NULL, 
  NRSERVICOCIAFILI NUMBER(10) NOT NULL, 
  CDCLASSE VARCHAR2(4) NOT NULL, 
  CDCICLO VARCHAR2(4) NOT NULL, 
  NRSEQPRECO NUMBER(10) NOT NULL, 
  QTPAXINICIAL NUMBER(10) NOT NULL, 
  QTPAXFINAL NUMBER(10) NOT NULL, 
  VRPRESERVPRO DOUBLE PRECISION NOT NULL, 
  VRPRESERVDPRO DOUBLE PRECISION NOT NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  DTINCLUSAO DATE NOT NULL, 
  DTULTATU DATE NOT 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_PROPRECOSEM PRIMARY KEY(CDFILIAL, CDCIA, NRTABPRECO, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, NRSEQPRECO, QTPAXINICIAL, NRORG)
)
/
ALTER TABLE PROPRECOSEM ADD CONSTRAINT FKCOC00328PRECOSECIAM FOREIGN KEY (CDFILIAL, CDCIA, NRTABPRECO, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, NRORG) REFERENCES PRECOSECIAM (CDFILIAL, CDCIA, NRTABPRECO, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, NRORG)
/
ALTER TABLE PROPRECOSEM ADD CONSTRAINT CKC_IDATIVO_PROPRECOSEM CHECK (IDATIVO in ('S','N'))
/
CREATE TABLE FRCICLOSERM (
  CDFILIAL VARCHAR2(4) NOT NULL, 
  CDCIA VARCHAR2(4) NOT NULL, 
  NRVOO VARCHAR2(5) NOT NULL, 
  CDTRECHO VARCHAR2(4) NOT NULL, 
  NRSERVICOCIAFILI NUMBER(10) NOT NULL, 
  CDCLASSE VARCHAR2(4) NOT NULL, 
  CDCICLO VARCHAR2(4) NOT NULL, 
  DTCICLOSER DATE NOT NULL, 
  CDCICLOSER VARCHAR2(4) NOT NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  DTINCLUSAO DATE NOT NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NOT NULL, 
  DTULTATU DATE NOT NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NOT NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NOT NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL,
  CONSTRAINT PK_FRCICLOSERM PRIMARY KEY(CDFILIAL, CDCIA, NRVOO, CDTRECHO, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, DTCICLOSER, NRORG)
)
/
ALTER TABLE FRCICLOSERM ADD CONSTRAINT CKC_IDATIVO_FRCICLOSERM CHECK (IDATIVO in ('S','N'))
/
alter table FRCICLOSERM
    add constraint FKCOC00332SERVCICLO foreign key  (CDFILIAL, CDCIA, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, NRORG)
      references SERVCICLO (CDFILIAL, CDCIA, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, NRORG)
/
create index COC00329_FK on FRCICLOSERM (CDCLASSE asc, CDCICLO asc, NRSERVICOCIAFILI asc, NRORG asc)
/
create index COC00330_FK on FRCICLOSERM (CDCIA asc, CDFILIAL asc, NRVOO asc, CDTRECHO asc, NRORG asc)
/
create index COC00331_FK on FRCICLOSERM (CDCICLOSER asc, NRORG asc)
/
alter table FRCICLOSERM
    add constraint FKCOC00333VOOTRECHO foreign key  (CDFILIAL, CDCIA, NRVOO, CDTRECHO, NRORG)
       references VOOTRECHO (CDFILIAL, CDCIA, NRVOO, CDTRECHO, NRORG)
/
alter table FRCICLOSERM
    add constraint FKCOC00334CICLOCIA foreign key  (CDFILIAL, CDCIA, CDCICLOSER, NRORG)
       references CICLOCIA (CDFILIAL, CDCIA, CDCICLO, NRORG)
/
CREATE INDEX COC00334_FK ON FRCICLOSERM (CDFILIAL, CDCIA, CDCICLOSER, NRORG)
/
CREATE TABLE PADVOOTREM (
  CDFILIAL VARCHAR2(4) NOT NULL, 
  CDCIA VARCHAR2(4) NOT NULL, 
  NRVOO VARCHAR2(5) NOT NULL, 
  CDTRECHO VARCHAR2(4) NOT NULL, 
  NRSERVICOCIAFILI NUMBER(10) NOT NULL, 
  CDCLASSE VARCHAR2(4) NOT NULL, 
  CDCICLO VARCHAR2(4) NOT NULL, 
  QTSERVOO DOUBLE PRECISION NOT NULL, 
  VRLOADSEVOO DOUBLE PRECISION NOT NULL, 
  NRPROPAXVOO DOUBLE PRECISION NOT NULL, 
  IDPROPSEVOO VARCHAR2(1) NOT NULL, 
  QTSESTBYVOO DOUBLE PRECISION NOT NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  DTINCLUSAO DATE NOT NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NOT NULL, 
  DTULTATU DATE NOT NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NOT NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NOT NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  CDSERVICO VARCHAR2(10) DEFAULT NULL NULL, 
  CDARVSERV VARCHAR2(20) DEFAULT NULL NULL,
  CONSTRAINT PK_PADVOOTREM PRIMARY KEY(CDFILIAL, CDCIA, NRVOO, CDTRECHO, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, NRORG)
)
/
ALTER TABLE PADVOOTREM ADD CONSTRAINT CKC_IDPROPSEVOO CHECK (IDPROPSEVOO in ('1','2','3','4','5'))
/
ALTER TABLE PADVOOTREM ADD CONSTRAINT CKC_IDATIVO_PADVOOTREM CHECK (IDATIVO in ('S','N'))
/
alter table PADVOOTREM
   add constraint FKCOC00335SERVCICLO foreign key  (CDFILIAL, CDCIA, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, NRORG)
    references SERVCICLO (CDFILIAL, CDCIA, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, NRORG)
/
alter table PADVOOTREM
    add constraint FKCOC00001VOOTRECH foreign key  (CDFILIAL, CDCIA, NRVOO, CDTRECHO, NRORG)
       references VOOTRECHO (CDFILIAL, CDCIA, NRVOO, CDTRECHO, NRORG)
/
CREATE TABLE PROPSERVICOM (
  CDFILIAL VARCHAR2(4) NOT NULL, 
  CDCIA VARCHAR2(4) NOT NULL, 
  NRVOO VARCHAR2(5) NOT NULL, 
  CDTRECHO VARCHAR2(4) NOT NULL, 
  NRSERVICOCIAFILI NUMBER(10) NOT NULL, 
  CDCLASSE VARCHAR2(4) NOT NULL, 
  CDCICLO VARCHAR2(4) NOT NULL, 
  QTPAXDE DOUBLE PRECISION NOT NULL, 
  QTPAXATE DOUBLE PRECISION NOT NULL, 
  QTSERVICO DOUBLE PRECISION NOT NULL, 
  NRORG NUMBER(10) DEFAULT 1 NOT NULL, 
  DTINCLUSAO DATE NOT NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NOT NULL, 
  DTULTATU DATE NOT NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NOT NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NOT NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL,
  CONSTRAINT PK_PROPSERVICOM PRIMARY KEY(CDFILIAL, CDCIA, NRVOO, CDTRECHO, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, QTPAXDE, NRORG)
)
/
ALTER TABLE PROPSERVICOM ADD CONSTRAINT FKCOC00337PADVOOTREM FOREIGN KEY (CDFILIAL, CDCIA, NRVOO, CDTRECHO, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, NRORG) REFERENCES PADVOOTREM (CDFILIAL, CDCIA, NRVOO, CDTRECHO, NRSERVICOCIAFILI, CDCLASSE, CDCICLO, NRORG)
/
ALTER TABLE PROPSERVICOM ADD CONSTRAINT CKC_IDATIVO_PROPSERVICOM CHECK (IDATIVO in ('S','N'))