DECLARE v_count NUMBER:=0;
BEGIN
SELECT 1 INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'CONFIGURACAOBOLETOEMAIL' ;
EXCEPTION
WHEN NO_DATA_FOUND THEN
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE CONFIGURACAOBOLETOEMAIL(
  ID INT NOT NULL,
	TEMPOPROCESSAMENTO INT,
	DATAINICIO DATE,
	DETALHAMENTO NUMERIC (1,0) DEFAULT 0,
	SERVIDORSMTP VARCHAR2 (254),
	PORTA CHAR(10),
	USUARIO	VARCHAR2 (254),
	SENHA VARCHAR2 (254),
	PROTOCOLO NUMERIC (1,0),
	ASSUNTO	VARCHAR2 (254),
	MENSAGEM VARCHAR2 (1000),
	URLLOGOTIPO VARCHAR2(254),
	URLIMAGENSCODIGOBARRAS VARCHAR2(254),
	RUSUARIO INT,
	ATUALIZADOEM DATE
)';
EXECUTE IMMEDIATE 'alter table CONFIGURACAOBOLETOEMAIL ADD CONSTRAINT PK_CONFIGURACAOBOLETOEMAIL PRIMARY KEY (ID)';
EXECUTE IMMEDIATE 'CREATE SEQUENCE CONFIGURACAOBOLETOEMAIL_SEQ MINVALUE 1
MAXVALUE 999999999999999999999999999 INCREMENT BY 1 NOCYCLE NOORDER' ;
END;
END;
/

DECLARE v_count NUMBER:=0;
BEGIN
SELECT 1 INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'CONTROLEBOLETOEMAIL' ;
EXCEPTION
WHEN NO_DATA_FOUND THEN
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE CONTROLEBOLETOEMAIL(
	ID INT NOT NULL,
	NUMPED INT,
	NUMORD INT,
	RDOCDEORIGEM INT,
	EMISSAO	DATE,
	DATAENVIO DATE,
	SITUACAOENVIO NUMERIC (1,0) DEFAULT 0,
	SITUACAOERRO NUMERIC (1,0) DEFAULT 0
)';
EXECUTE IMMEDIATE 'alter table CONTROLEBOLETOEMAIL ADD CONSTRAINT PK_CONTROLEBOLETOEMAIL PRIMARY KEY (ID)';
EXECUTE IMMEDIATE 'CREATE SEQUENCE CONTROLEBOLETOEMAIL_SEQ MINVALUE 1
MAXVALUE 999999999999999999999999999 INCREMENT BY 1 NOCYCLE NOORDER' ;
END;
END;
/

DECLARE v_count NUMBER:=0;
BEGIN
SELECT 1 INTO v_count FROM USER_TABLES WHERE UPPER(table_name) = 'HISTORICOBOLETOEMAIL' ;
EXCEPTION
WHEN NO_DATA_FOUND THEN
BEGIN
EXECUTE IMMEDIATE 'CREATE TABLE HISTORICOBOLETOEMAIL(
	RIDCONTROLEBOLETOEMAIL	INT,
	RUSUARIO INT,
	ATUALIZADOEM DATE,
	HISTORICO VARCHAR2(1000)
)';
END;
END;
/

