
/*------ ATD 341069 ------*/
MERGE into ITEM using dual on (oid = 38731) when not matched then 
insert (rescopo, criadopor, atualizadopor, codigo, criadoem, atualizadoem , observacao, nome, cid, oid, excluido) 
values (7, 1, 1, '', '01/01/01', '01/01/01', '','SkyHub', 18, 38731, 0);
MERGE into ITEM using dual on (oid = 38730) when not matched then 
insert (rescopo, criadopor, atualizadopor, codigo, criadoem, atualizadoem , observacao, nome, cid, oid, excluido) 
values (7, 1, 1, '', '01/01/01', '01/01/01', '','Ciashop', 18, 38730, 0);
MERGE into ITEM using dual on (oid = 38729) when not matched then 
insert (rescopo, criadopor, atualizadopor, codigo, criadoem, atualizadoem , observacao, nome, cid, oid, excluido) 
values (7, 1, 1, '', '01/01/01', '01/01/01', '','VTEX', 18, 38729, 0);

MERGE into CATEGORIA using dual on (oid = 38731) when not matched then 
insert (rsuper, nomeinterno, oid) values (38601, 'TIPO_DE_INTEGRACAO_SKYHUB', 38731);
MERGE into CATEGORIA using dual on (oid = 38730) when not matched then 
insert (rsuper, nomeinterno, oid) values (38601, 'TIPO_DE_INTEGRACAO_CIASHOP', 38730);
MERGE into CATEGORIA using dual on (oid = 38729) when not matched then 
insert (rsuper, nomeinterno, oid) values (38601, 'TIPO_DE_INTEGRACAO_VTEX', 38729);

commit;


DECLARE v_count NUMBER:=0;

BEGIN

SELECT Count(1) INTO v_count FROM USER_TAB_COLUMNS WHERE UPPER(table_name) = 'PEDICLICAD' AND Upper(COLUMN_NAME) = 'REFERENCIA' AND DATA_LENGTH < 100;

IF v_count > 0 THEN

EXECUTE IMMEDIATE 'ALTER TABLE PEDICLICAD MODIFY REFERENCIA VARCHAR2(100)';

END IF;

SELECT Count(1) INTO v_count FROM USER_TAB_COLUMNS WHERE UPPER(table_name) = 'PEDICLICOMPLEMENTO' AND Upper(COLUMN_NAME) = 'NUMPEDECOMMERCE';

IF v_count > 0 THEN

EXECUTE IMMEDIATE 'ALTER TABLE PEDICLICOMPLEMENTO DROP COLUMN NUMPEDECOMMERCE';

END IF;

SELECT Count(1) INTO v_count FROM USER_TAB_COLUMNS WHERE UPPER(table_name) = 'PEDICLICOMPLEMENTO' AND Upper(COLUMN_NAME) = 'OIDORIGEMNUMPEDECOMMERCE';

IF v_count > 0 THEN

EXECUTE IMMEDIATE 'ALTER TABLE PEDICLICOMPLEMENTO RENAME COLUMN OIDORIGEMNUMPEDECOMMERCE TO OIDREFERENCIA';

END IF;

END;

