
/*------ ATD 472025 ------*/
DECLARE v_count NUMBER:=0;
BEGIN
   SELECT 1 INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'GERENCIAMENTOPEDIDO' ;
   EXCEPTION
   WHEN NO_DATA_FOUND THEN
      BEGIN
        EXECUTE IMMEDIATE 'CREATE TABLE GERENCIAMENTOPEDIDO(
        ID int identity NOT NULL,
        CODPRO Char(5),
        NUMPED INT,
        ITEMPEDIDO INT,
        STATUS INT,
        OBSERVACAO VARCHAR(254),
        ATUALIZADOEM DATE,
        OIDUSUARIO);

        EXECUTE IMMEDIATE 'alter table GERENCIAMENTOPEDIDO ADD CONSTRAINT PK_GERENCIAMENTOPEDIDO PRIMARY KEY (ID)'; 
        EXECUTE IMMEDIATE 'CREATE SEQUENCE GERENCIAMENTOPEDIDO_SEQ MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 NOCYCLE NOORDER' ;
        EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER GERENCIAMENTOPEDIDO_I
        BEFORE INSERT ON GERENCIAMENTOPEDIDO for each ROW
        WHEN (new.ID IS NULL)
            BEGIN
                SELECT GERENCIAMENTOPEDIDO_SEQ.NEXTVAL INTO :new.ID FROM dual;
            END;';
     END;
END;

/*------ ATD 472922 ------*/
DECLARE v_count NUMBER:=0;
BEGIN
   SELECT 1 INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'GERENCIAMENTOPEDIDOSTATUS' ;
   EXCEPTION
   WHEN NO_DATA_FOUND THEN
      BEGIN
        EXECUTE IMMEDIATE 'CREATE TABLE GERENCIAMENTOPEDIDOSTATUS(
        ID int identity NOT NULL,
        PARAMETRO INT,
        STATUS INT,
        FILIAL CHAR(2),
        ATUALIZADOEM DATE,
        OIDUSUARIO);

        EXECUTE IMMEDIATE 'alter table GERENCIAMENTOPEDIDOSTATUS ADD CONSTRAINT PK_GERENCIAMENTOPEDIDOSTATUS PRIMARY KEY (ID)'; 
        EXECUTE IMMEDIATE 'CREATE SEQUENCE GERENCIAMENTOPEDIDOSTATUS_SEQ MINVALUE 1 MAXVALUE 999999999999999999999999999 INCREMENT BY 1 NOCYCLE NOORDER' ;
        EXECUTE IMMEDIATE 'CREATE OR REPLACE TRIGGER GERENCIAMENTOPEDIDOSTATUS_I
        BEFORE INSERT ON GERENCIAMENTOPEDIDOSTATUS for each ROW
        WHEN (new.ID IS NULL)
            BEGIN
                SELECT GERENCIAMENTOPEDIDOSTATUS_SEQ.NEXTVAL INTO :new.ID FROM dual;
            END;';
     END;
END;
