CREATE TABLE ITEMORCAGOP (
  NRORCAMENTOGOP NUMBER(10) NOT NULL, 
  NRITEMORCAOP NUMBER(10) NOT NULL, 
  IDENTRSAIDOP VARCHAR2(1) DEFAULT NULL NULL, 
  CDTIPOOPER VARCHAR2(2) DEFAULT NULL NULL, 
  CDORCAMENTOMO VARCHAR2(10) DEFAULT NULL NULL, 
  CDDESPPREV VARCHAR2(3) DEFAULT NULL NULL, 
  CDFILIAL VARCHAR2(4) DEFAULT NULL NULL, 
  CDFILIALMO VARCHAR2(4) DEFAULT NULL NULL, 
  CDSERVFILI VARCHAR2(5) DEFAULT NULL NULL, 
  CDIMPOSTO VARCHAR2(2) DEFAULT NULL NULL, 
  DTMESBASEITEM DATE DEFAULT NULL NULL, 
  IDTIPOORCAOP VARCHAR2(30) DEFAULT 'FATURAMENTO' NOT NULL, 
  NRORG NUMBER(10) DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL, 
  IDATIVO VARCHAR2(1) DEFAULT 'S' NOT NULL, 
  DTINCLUSAO DATE DEFAULT NULL NULL, 
  DTULTATU DATE DEFAULT NULL NULL, 
  NRORGINCLUSAO NUMBER(10) DEFAULT 1 NULL, 
  NRORGULTATU NUMBER(10) DEFAULT 1 NULL, 
  CDOPERINCLUSAO VARCHAR2(12) DEFAULT '1' NULL, 
  CDOPERULTATU VARCHAR2(12) DEFAULT '1' NULL,
  CONSTRAINT PK_ITEMORCAGOP PRIMARY KEY(NRITEMORCAOP)
)
/
ALTER TABLE ITEMORCAGOP ADD CONSTRAINT CKC_IDATIVO_ITEMORCAGOP CHECK (IDATIVO IN ('S','N'))
/
ALTER TABLE ITEMORCAGOP ADD CONSTRAINT CKC_ITEMORCAGOP_IDTIPOORCAOP CHECK (IDTIPOORCAOP IN ('FATURAMENTO', 'CONSUMO', 'MAOOBRA', 'DESPMATRIZ', 'DESPDIVERSA', 'DESPENTRADA', 'LIQUIDO', 'IMPOSTO', 'IMPOSTOARECUPERAR', 'IMPOSTOSOBLUCRO',  'INVESTIMENTO', 'DEPRECIACAO', 'TAXAADM'))
/
ALTER TABLE ITEMORCAGOP ADD CONSTRAINT CKC_IDENTRSAIDOP_ITEMORCAGOP CHECK (IDENTRSAIDOP IS NULL OR (IDENTRSAIDOP IN ('E','S')))
/
ALTER TABLE ITEMORCAGOP  ADD CONSTRAINT FKGOP00684ORCAMENTOGOP FOREIGN KEY (NRORCAMENTOGOP) REFERENCES ORCAMENTOGOP (NRORCAMENTOGOP) ON DELETE CASCADE
/
ALTER TABLE ITEMORCAGOP ADD CONSTRAINT FKGOP00685TIPOOPERAC FOREIGN KEY (CDTIPOOPER, IDENTRSAIDOP) REFERENCES TIPOOPERAC (CDTIPOOPER, IDENTRSAIDOP)
/
ALTER TABLE ITEMORCAGOP ADD CONSTRAINT FKGOP00686ORCAMENTOMO FOREIGN KEY (CDORCAMENTOMO, CDFILIALMO) REFERENCES ORCAMENTOMO (CDORCAMENTOMO, CDFILIAL)
/
ALTER TABLE ITEMORCAGOP ADD CONSTRAINT FKGOP00687DESPPREV FOREIGN KEY (CDDESPPREV) REFERENCES DESPPREV (CDDESPPREV)
/
ALTER TABLE ITEMORCAGOP ADD CONSTRAINT FKGOP00688SERVICO FOREIGN KEY (CDFILIAL, CDSERVFILI) REFERENCES SERVICO (CDFILIAL, CDSERVFILI)
/
ALTER TABLE ITEMORCAGOP ADD CONSTRAINT FKGOP00689IMPOSTO FOREIGN KEY (CDIMPOSTO) REFERENCES IMPOSTO (CDIMPOSTO)