ALTER TABLE HABILOPER ADD VRCUSHRHABILOP FLOAT NULL    
/ 

ALTER TABLE HABILOPER ADD IDSITUACAOHABILOP VARCHAR2(1) NULL    
        CONSTRAINT CKC_IDSITUACAOHABILOP CHECK (IDSITUACAOHABILOP IS NULL OR (IDSITUACAOHABILOP IN ('A','I'))) 
/

CREATE TABLE APRCUSOPERA
(
  CDFILIAL                 	VARCHAR2(4)  	NOT NULL, 
  NRORDPROD         	VARCHAR2(10)	NOT NULL, 
  NRSUBORDPROD  	VARCHAR2(1)  	NOT NULL,
  CDETAPAPROD      	VARCHAR2(10) 	NOT NULL, 
  NRAPRCUSTOP      	VARCHAR2(10) 	NOT NULL,
  CDOPERADOR        	VARCHAR2(12) 	NOT NULL,
  VRCUSTOOPER      	FLOAT   		NULL,
  QTHROPER            	FLOAT   		NULL,
   NRORG                       	NUMBER              	DEFAULT 1 NOT NULL, 
   IDATIVO                    	VARCHAR2(1)     	DEFAULT 'S' NOT NULL
      CONSTRAINT CKC_IDATIVO_APRCUSOPERA CHECK (IDATIVO IN ('S','N')),
   DTINCLUSAO             DATE                   	NULL,
   DTULTATU                  	DATE                  	NULL,
   NRORGINCLUSAO    NUMBER             	DEFAULT 1 NULL,
   CDOPERINCLUSAO  VARCHAR2(12)  	DEFAULT '1' NULL,
   NRORGULTATU          NUMBER             	DEFAULT 1 NULL,
   CDOPERULTATU        VARCHAR2(12)  	DEFAULT '1',
	CONSTRAINT PK_APRCUSOPERA PRIMARY KEY (CDFILIAL, NRORDPROD, NRSUBORDPROD, CDETAPAPROD, NRAPRCUSTOP, CDOPERADOR)
 )
/

CREATE INDEX FK_MAN02303 ON APRCUSOPERA (CDFILIAL ASC, NRORDPROD ASC, NRSUBORDPROD ASC)
/

ALTER TABLE APRCUSOPERA
    ADD CONSTRAINT  FKMAN02303ORDPRODU FOREIGN KEY  (CDFILIAL, NRORDPROD, NRSUBORDPROD)
       REFERENCES ORDPRODUCAO (CDFILIAL, NRORDPROD, NRSUBORDPROD) ON DELETE CASCADE
/

CREATE INDEX FK_MAN02304 ON APRCUSOPERA (CDOPERADOR ASC)
/

ALTER TABLE APRCUSOPERA
    ADD CONSTRAINT FKMAN02304OPERADOR FOREIGN KEY  (CDOPERADOR)
       REFERENCES OPERADOR (CDOPERADOR)
/

CREATE INDEX FK_MAN02305 ON APRCUSOPERA (NRAPRCUSTOP ASC, CDOPERADOR ASC) 