ALTER TABLE PARCMPSUP ADD QTDIASBLOQGRAV NUMBER
/

ALTER TABLE PARCMPSUP ADD QTDIASBLOQAPROV NUMBER
/

CREATE TABLE APROVNECECMPEXTRA (
    NRAPROVNECECMPEXTRA NUMBER 			NOT NULL,
    NRNIVELAPROV        NUMBER 			NOT NULL,
    CDFILIAL            VARCHAR2(4) 	NOT NULL,
    CDOPERADOR          VARCHAR2(12) 	NOT NULL,
    IDTIPO              VARCHAR2(6) 	NOT NULL,        
    QTDEAPROVNIVEL      NUMBER 			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',
		CONSTRAINT CKC_IDATIVO_APROVNECECMPEXTRA CHECK (IDATIVO IN ('S','N')),
		CONSTRAINT CKC_IDTIPO_APROVNECECMPEXTRA CHECK (IDTIPO IN ('GO','GU', 'PLA', 'OUTROS')),
		CONSTRAINT PK_APROVNECECMPEXTRA PRIMARY KEY(NRAPROVNECECMPEXTRA),
		CONSTRAINT UN_APROVNECECMPEXTRA UNIQUE(CDFILIAL, CDOPERADOR)
)
/

CREATE SEQUENCE SEQ_APROVNECECMPEXTRA INCREMENT BY 1 MINVALUE 1
/

CREATE TABLE OPRELACAPROVNECEXTRA (
    NROPRELACAPROVNECEXTRA NUMBER 		   NOT NULL,
    NRAPROVNECECMPEXTRA    NUMBER 		   NOT NULL,
    CDFILIAL               VARCHAR2(4) 	   NOT NULL,
    CDOPERADOR             VARCHAR2(12)    NOT NULL,
    CDRELACOPER            VARCHAR2(12)    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',
		CONSTRAINT CKC_IDATIVO_OPRELACPROVECEXTRA CHECK (IDATIVO IN ('S','N')),
		CONSTRAINT PK_OPRELACAPROVNECEXTRA PRIMARY KEY(NROPRELACAPROVNECEXTRA),
		CONSTRAINT UN_OPRELACAPROVNECEXTRA UNIQUE(CDFILIAL, CDOPERADOR, CDRELACOPER),
		CONSTRAINT FKSUP00686NRAPROVNECECMPEXTRA FOREIGN KEY (NRAPROVNECECMPEXTRA) 
										  REFERENCES APROVNECECMPEXTRA(NRAPROVNECECMPEXTRA) ON DELETE CASCADE
)
/

CREATE INDEX SUP00686_FK ON OPRELACAPROVNECEXTRA (NRAPROVNECECMPEXTRA)
/

CREATE SEQUENCE SEQ_OPRELACAPROVNECEXTRA INCREMENT BY 1 MINVALUE 1
/