declare 
  object_exists exception;
  except_01451  exception;
  except_01442  exception;

  pragma exception_init (object_exists , -01430);
  pragma exception_init (except_01451  , -01451);
  pragma exception_init (except_01442  , -01442);
begin 
  execute immediate 'ALTER TABLE BOLETO ADD CONVENIOCAMPANHA_ID NUMBER(7,0)';
  exception 
    when object_exists  then null;
    when except_01451  then null;
    when except_01442  then null;
end;
/


declare
  object_exists  exception;
  except_02275  exception;
  except_02270  exception;
  except_02261  exception;

  pragma exception_init (object_exists  , -01430);
  pragma exception_init (except_02275  , -02275);
  pragma exception_init (except_02270  , -02270);
  pragma exception_init (except_02261  , -02261);
begin
  execute immediate 'ALTER TABLE BOLETO
   ADD CONSTRAINT FK_BOLETO_CONVENIOCAMPANHA
   FOREIGN KEY (CONVENIOCAMPANHA_ID)
   REFERENCES CONVENIO (CONVENIO_ID)';
  exception 
    when object_exists  then null;
    when except_02275  then null;
    when except_02270  then null;
    when except_02261  then null;
end;
/

declare 
  object_exists exception;
  except_01451  exception;
  except_01442  exception;

  pragma exception_init (object_exists , -01430);
  pragma exception_init (except_01451  , -01451);
  pragma exception_init (except_01442  , -01442);
begin 
  execute immediate 'ALTER TABLE CAJA ADD CONVENIOCAMPANHA_ID NUMBER(7,0)';
  exception 
    when object_exists  then null;
    when except_01451  then null;
    when except_01442  then null;
end;
/


declare
  object_exists  exception;
  except_02275  exception;
  except_02270  exception;
  except_02261  exception;

  pragma exception_init (object_exists  , -01430);
  pragma exception_init (except_02275  , -02275);
  pragma exception_init (except_02270  , -02270);
  pragma exception_init (except_02261  , -02261);
begin
  execute immediate 'ALTER TABLE CAJA
   ADD CONSTRAINT FK_CAJA_CONVENIOCAMPANHA
   FOREIGN KEY (CONVENIOCAMPANHA_ID)
   REFERENCES CONVENIO (CONVENIO_ID)';
  exception 
    when object_exists  then null;
    when except_02275  then null;
    when except_02270  then null;
    when except_02261  then null;
end;
/



declare
    object_exists exception;
    pragma exception_init (object_exists , -00955);
begin
  execute immediate 'CREATE TABLE CAMPANHACUPOMSORTEADO (
    CAMPANHACUPOMSORTEADO_ID NUMBER(7,0) NOT NULL ENABLE, 
    BOLETOSORTEADO_ID NUMBER(15,0), 
    BOLETOCUPOM_ID NUMBER(15,0), 		
	CONVENIO_ID NUMBER(7,0), 
	PUNTOVENTA_ID NUMBER(7,0),
    EMPRESA_ID NUMBER(7,0),
    CODIGOCUPOM VARCHAR2(40 BYTE),
	ACTIVO NUMBER(1,0), 
	FECMODIF DATE,
    FECCREACION DATE,  
	USUARIO_ID NUMBER(7,0), 
    PRIMARY KEY (CAMPANHACUPOMSORTEADO_ID),
   	FOREIGN KEY (BOLETOSORTEADO_ID)
	REFERENCES BOLETO (BOLETO_ID) ENABLE,
    FOREIGN KEY (BOLETOCUPOM_ID)
	REFERENCES BOLETO (BOLETO_ID) ENABLE,
	FOREIGN KEY (PUNTOVENTA_ID)
	REFERENCES PUNTO_VENTA (PUNTOVENTA_ID) ENABLE,
	FOREIGN KEY (EMPRESA_ID)
	REFERENCES EMPRESA (EMPRESA_ID) ENABLE,
    FOREIGN KEY (CONVENIO_ID)
	REFERENCES CONVENIO (CONVENIO_ID) ENABLE )';
  exception when object_exists then null;
end;
/

declare
    object_exists exception;
    pragma exception_init (object_exists , -00955);
begin
  execute immediate 'CREATE SEQUENCE CAMPANHACUPOMSORTEADO_SEQ INCREMENT BY 1 START WITH 1 NOCACHE ORDER NOCYCLE';
  exception when object_exists then null;
end;