CREATE TABLE UPDATERCONFIG
(
  ID              NUMBER NOT NULL,
  CDFILIAL        VARCHAR2(4) NOT NULL,
  CONFIG          VARCHAR2(4000) NOT NULL,
  
  NRORG           NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
  DTINCLUSAO      DATE DEFAULT SYSDATE,
  DTULTATU        DATE DEFAULT SYSDATE,
  NRORGINCLUSAO   NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
  NRORGULTATU     NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
  
  CONSTRAINT PK_UPDATERCONFIG PRIMARY KEY (ID),
  CONSTRAINT FK_UPDATERCONFIGFILIAL FOREIGN KEY (CDFILIAL) REFERENCES FILIAL (CDFILIAL)
);
/
CREATE SEQUENCE SEQ_UPDATERCONFIG START WITH 1 MINVALUE 1 INCREMENT BY 1;
/
CREATE OR REPLACE TRIGGER GERA_ID_UPDATERCONFIG
BEFORE INSERT ON UPDATERCONFIG FOR EACH ROW
BEGIN
  SELECT SEQ_UPDATERCONFIG.NEXTVAL
    INTO :NEW.ID
    FROM DUAL;
END;
/

CREATE TABLE UPDATERCONFIGHIST
(
  ID              NUMBER NOT NULL,
  UPDATERCONFIGID NUMBER NOT NULL,
  CDOPERADOR      VARCHAR2(12) NOT NULL,
  CONFIG          VARCHAR2(4000) NOT NULL,
  
  NRORG           NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
  DTINCLUSAO        DATE DEFAULT SYSDATE,
  DTULTATU          DATE DEFAULT SYSDATE,
  NRORGINCLUSAO   NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
  NRORGULTATU     NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
  
  CONSTRAINT PK_UPDATERCONFIGHIST PRIMARY KEY (ID),
  CONSTRAINT FK_UPDATERCONFIGHISTCONFIGID FOREIGN KEY (UPDATERCONFIGID) REFERENCES UPDATERCONFIG (ID),
  CONSTRAINT FK_UPDATERCONFIGHISTOPER FOREIGN KEY (CDOPERADOR) REFERENCES OPERADOR (CDOPERADOR)
);
/
CREATE SEQUENCE SEQ_UPDATERCONFIGHIST START WITH 1 MINVALUE 1 INCREMENT BY 1;
/
CREATE OR REPLACE TRIGGER GERA_ID_UPDATERCONFIGHIST
BEFORE INSERT ON UPDATERCONFIGHIST FOR EACH ROW
BEGIN
  SELECT SEQ_UPDATERCONFIGHIST.NEXTVAL
    INTO :NEW.ID
    FROM DUAL;
END;
/

CREATE TABLE UPDATERPRODCONFIG
(
  ID              NUMBER NOT NULL,
  CDPRODUCTID     VARCHAR2(4) NOT NULL,
  NRVERSAO        VARCHAR2(10)  NOT NULL,
  CONFIG          VARCHAR2(4000) NULL,
  
  NRORG           NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NOT NULL,
  DTINCLUSAO      DATE DEFAULT SYSDATE,
  DTULTATU        DATE DEFAULT SYSDATE,
  NRORGINCLUSAO   NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
  NRORGULTATU     NUMBER DEFAULT SYS_CONTEXT('nrorg_ctx','nrorg') NULL,
  
  CONSTRAINT PK_UPDATERPRODCONFIG PRIMARY KEY (ID)
);
/
CREATE SEQUENCE SEQ_UPDATERPRODCONFIG START WITH 1 MINVALUE 1 INCREMENT BY 1;
/
CREATE OR REPLACE TRIGGER GERA_ID_UPDATERPRODCONFIG
BEFORE INSERT ON UPDATERPRODCONFIG FOR EACH ROW
BEGIN
  SELECT SEQ_UPDATERPRODCONFIG.NEXTVAL
    INTO :NEW.ID
    FROM DUAL;
END;
/