CREATE TABLE FCT_HIERARQUIAOPER (
   NRHIERARQUIAOPER 	NUMBER       	NOT NULL,
   CDOPERADOR      		VARCHAR2(12) 	NOT NULL,
   CDFILIAL         	VARCHAR2(4),
   NRHIERARQUIAPAI  	NUMBER,
   IDOPERMASTER     	VARCHAR2(1),
   NRORG                NUMBER 			DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
   IDATIVO              VARCHAR2(1)     DEFAULT 'S' NOT NULL
		CONSTRAINT CKC_IDATIVO_FCT_HIERAOPER CHECK (IDATIVO IN ('S','N')), 
   DTINCLUSAO           DATE            NULL,
   DTULTATU             DATE            NULL,
   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 PK_FCTHROPER_NRHIERARQUIAOPER PRIMARY KEY (NRHIERARQUIAOPER)
)
/

CREATE INDEX SM00270_FK ON FCT_HIERARQUIAOPER (CDOPERADOR ASC)
/

ALTER TABLE FCT_HIERARQUIAOPER ADD  
	CONSTRAINT FKSM00270OPERADOR FOREIGN KEY (CDOPERADOR) 
		REFERENCES OPERADOR (CDOPERADOR) ON DELETE CASCADE
/

CREATE INDEX SM00271_FK ON FCT_HIERARQUIAOPER (CDFILIAL ASC)
/

ALTER TABLE FCT_HIERARQUIAOPER ADD 
	CONSTRAINT FKSM00271FILIAL FOREIGN KEY (CDFILIAL) 
		REFERENCES FILIAL (CDFILIAL)
/

ALTER TABLE FCT_HIERARQUIAOPER ADD CONSTRAINT CKC_FCTHIERAROPER_IDOPERMASTER CHECK(IDOPERMASTER IN ('S', 'N'))