CREATE TABLE HORACESSOPER (
    ID               NUMBER        	  NOT NULL,
    HORACESSOINI     VARCHAR2(5)   	  NOT NULL,
    HORACESSOFIM     VARCHAR2(5)      NOT NULL,
    CDOPERADOR       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 PK_HORACESSOPER          PRIMARY KEY(ID),
		CONSTRAINT FK_HORACESSOPER_OPER     FOREIGN KEY (CDOPERADOR) REFERENCES OPERADOR (CDOPERADOR),
		CONSTRAINT CKC_IDATIVO_HORACESSOPER CHECK (IDATIVO IN ('S','N'))
)
/

CREATE INDEX HORACESSOPER_OPER_FK ON HORACESSOPER (CDOPERADOR ASC)
/

CREATE TABLE HORACESSOPERDIA (
    ID                NUMBER          NOT NULL,
    HORACESSOPER_ID   NUMBER          NOT NULL,
    DIASEMANA         VARCHAR2(1)     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 PK_HORACESSOPERDIA          PRIMARY KEY(ID),
		CONSTRAINT FK_HORACESSOPERDIA_HRAC     FOREIGN KEY (HORACESSOPER_ID) REFERENCES HORACESSOPER (ID),
		CONSTRAINT CKC_IDATIVO_HORACESSOPERDIA CHECK (IDATIVO IN ('S','N'))
)
/

CREATE INDEX HORACESSOPERDIA_HRAC_FK ON HORACESSOPERDIA (HORACESSOPER_ID ASC)
/