declare
    begin
    execute immediate 'CREATE TABLE PRICING_ESPECIFICO_CATEGORIA(
PRICINGESPECIFICO_CATEGORIAID NUMBER(7,0),
PRICINGESPECIFICO_ID NUMBER (7,0),
CATEGORIA_ID NUMBER (7,0),
FECMODIF DATE,
USUARIO_ID NUMBER (7,0),
ACTIVO NUMBER (1,0),

CONSTRAINT PRICINGESPECIFICOCATEGORIA_PK PRIMARY KEY (PRICINGESPECIFICO_CATEGORIAID)
)';
	exception when others  then null;
end;
/
declare
    begin
    execute immediate 'ALTER TABLE PRICING_ESPECIFICO_CATEGORIA 
ADD CONSTRAINT PRICING_ESP_CAT_PRICING_ESP_FK FOREIGN KEY(PRICINGESPECIFICO_ID) REFERENCES PRICING_ESPECIFICO (PRICINGESPECIFICO_ID)';
	exception when others  then null;
end;
/
declare
    begin
    execute immediate 'ALTER TABLE PRICING_ESPECIFICO_CATEGORIA
ADD CONSTRAINT PRICING_ESP_CAT_PRICING_CAT_FK FOREIGN KEY(CATEGORIA_ID) REFERENCES CATEGORIA (CATEGORIA_ID)';
	exception when others  then null;
end;
/
declare
    begin
    execute immediate 'CREATE SEQUENCE PRICING_ESP_CATEGORIA_SEQ START WITH 1 INCREMENT BY 1';
	exception when others  then null;
end;
/
declare
begin
FOR R in(SELECT PE.PRICINGESPECIFICO_ID, PE.CATEGORIA_ID FROM PRICING_ESPECIFICO PE)
loop
  INSERT INTO PRICING_ESPECIFICO_CATEGORIA VALUES(PRICING_ESP_CATEGORIA_SEQ.nextVal, R.PRICINGESPECIFICO_ID, R.CATEGORIA_ID, current_date, 1, 1);
  end loop;
  exception when others  then null;
end;