MIGRACION- DEMORA EN TIEMPO DE MIGRACION
HOLA MI AMIGOS TENGO UNA INQUIETUD, TENGO 546767 REGISTRO QUE TENGO UN CURSOR QUE MIGRAR A 0RACLE 9i EL PROBLEMA ES QUE ESOS REGISTROS SE DEMORA 12 HORAS EN INSERTAR
CREATE OR REPLACE PROCEDURE MIGRAC_FTRD10K_CAT_PP_HIST1
IS
varCat_PPHH number;
varFecTrans date;
varCatPP number;
varIDTransaccion number;
varIDPer_PKY con_transaccion.transaccion_id%type;---number;
varNomVen varchar2(250);
varNroPre number;
varResTransf varchAr2(50);
varNroNot varchar2(2);
varTipMov varchar2(2);
varPorDer number(5,2);
varFecIns date;
--cont numeric;
---varFecDesde date; -----variable para fecha hasta
varFecMoviento date;
--VarCount numeric;
varNumPredio number;
varFecha1 date;
varFecha2 date;
--varFecha3 date;
---varFechaAux date;
varFecValantes date;
auxCadFech varchar2(30);
auxCont numeric;
segundos numeric;
--Segundos1 numeric;
--auxfech date; ----varible para fecha hasta
--varFecDesde date; -----variable para fecha hasta
BEGIN
--- cont:=0;
auxCont:=0;
varFecMoviento:=sysdate;
---VarCount:=1;
DECLARE CURSOR datos_predio
IS
----sentecia para sacar todos los predios
SELECT DISTINCT(FT.TDNROPRE) from SGM.FTRD10K FT;
cursor DATOS_CAT_PP_HIST(pred numeric)
is
-----permite sacar los datos de la tabla par insertar en la tabla cat_propie_pred_hist
select
ft.tdfectrf,
cat.prop_predio_id,
ct.transaccion_id,
per.per_id_pky,
ft.tdnomven,
ft.tdnropre,
ft.tdrestrf,
ft.tdnronot,
ft.tdtipmov,
ft.tdporder,
ft.tdfectrf
from ftrd10k_ftrd10k1 ft JOIN con_transaccion_prueba_v1 ct ON
ft.tdfecmov=ct.fecha and ft.tdnropre=pred JOIN per_persona per ON
ft.tdnomven=per.denominacion and per.num_identificacion is null join cat_propie_pred cat on cat.num_predio=pred
group by cat.prop_predio_id,ft.tdfectrf,ct.transaccion_id,per.per_id_pky,ft.tdnomven,ft.tdnropre , ft.tdrestrf,
ft.tdnronot,
ft.tdtipmov,
ft.tdporder,
ft.tdfecmov
order by ft.tdfectrf ASC;
BEGIN
OPEN datos_predio;
FOR i IN 1..800000 LOOP
FETCH datos_predio INTO varNroPre;
EXIT WHEN datos_predio%NOTFOUND;
open DATOS_CAT_PP_HIST(varNroPre);
for i in 1..800000 loop
fetch DATOS_CAT_PP_HIST INTO varFecTrans,varCatPP,varIDTransaccion,varIDPer_PKY,varNomVen,varNumPredio,varResTransf,varNroNot,varTipMov,varPorDer,varFecIns;
exit when DATOS_CAT_PP_HIST%NOTFOUND;
auxCadFech:=to_char(varFecTrans,'yyyy');
if(auxCont=0) then
if (auxCadFech is null) then
varFecha1:=null;
varFecha2:=null;
else
varFecha1:=to_date('01/01/'||to_char(varFecTrans,'yyyy')||' 00:00:01','dd/mm/yyyy hh24:mi:ss');-----para la fecha desde
segundos:=1;
varFecha2:=to_date(to_char(varFecTrans,'dd')||'/'||to_char(varFecTrans,'mm')||'/'||to_char(varFecTrans,'yyyy'),'dd/mm/yyyy'); ----fecha hasta o fecha original
end if;
if(varFecha1 is not null )then
varFecValantes:=varFecha1;
end if;
else ---para el auxCont
-----------------------------------------------------------------
if(varFecha1 is not null )then
varFecValantes:=varFecha1;
end if;
if (varFecValantes is null) then
if(varFecha2 is null )then
segundos:=segundos+1;
varFecha1:=null;
else
segundos:=segundos+1;
varFecha1:=fecha_mas_segundos_fun123(varFecha2,segundos);
end if;
else
if(varFecha2 is null ) then
segundos:=segundos+1;
varFecha1:=null;
else
if(trunc(varFecha2)=trunc(varFecValantes)) then
segundos:=segundos+1;
varFecha1:=fecha_mas_segundos_fun123(varFecha2,segundos);
else
segundos:=1;
varFecha1:=fecha_mas_segundos_fun123(varFecha2,segundos);
end if;
end if;
segundos:=segundos+1;
end if;
-----------------------------------------------------------------
/* if(cont=0) then
dia:=(to_char(varFecTrans,'dd'));
mes:=to_char(varFecTrans,'mm');
anio:=to_char(varFecTrans,'yyyy');
hora :=to_char(varFecTrans,'hh24');
minit := to_char(varFecTrans,'mi');
seg :=to_char(varFecTrans,'ss');
auxfech := to_date(to_char(dia)||'/'||to_char(mes)||'/'||to_char(anio)||' '||'00:00:01','dd/mm/yyyy hh24:mi:ss');
varSegundos:=1;
cont:=cont+1;
else
if (trunc(auxfech)=trunc(varFecTrans)) then
varSegundos :=varSegundos+1;
auxfech :=fecha_mas_segundos_fun123(varFecTrans,varSegundos);
else
varSegundos :=1;
auxfech :=fecha_mas_segundos_fun123(varFecTrans,varSegundos);
end if;
cont:=cont+1;
end if; */
auxCont:=auxCont+1;
end if; ----para el incremento del contador auxCont
select cat_pp_hist_sec.nextval into varCat_PPHH from dual ;
insert into CAT_PROPIE_PRE_HIST_PRUEBA (PROP_PREDIO_ID_HIST,PROP_PREDIO_ID,PERSONA_ID,NUM_PREDIO,TRANSACCION_ID,PORCEN_DDAA,NOTARIA,FEC_INSCRIPCION,FEC_MODREGISTRO,USUARIO,ESTADO,FEC_RIGE_DESDE,FEC_RIGE_HASTA)
values
(
varCat_PPHH,varCatPP,varIDPer_PKY,varNumPredio,varIDTransaccion,varPorDer,varNroNot,varFecIns,varFecMoviento,varResTransf,varTipMov,varFecha1,varFecTrans);
commit;
end loop;
close DATOS_CAT_PP_HIST;
END LOOP;
CLOSE datos_predio;
-- VarCount:=VarCount+1;
END;
END;
YA LE PUESE EN EL FOR 800000 PERO PORQUE ESTA 800000000 TODAVIA SIQGUE LENTO
TAMBIEN TENGO UNA DUDA SEGUN LO QUE HE LEIDO DICE QUE EL CURSOR TERMINA CUANDO YA NO EXISTE REGISTROS Y LOS QUE ESTA EN EL FOR 800000000 DEJEN DE FUNCIONAR, ES VERDAD ESO
EXISTE DE LAGUNA FORMA DE HACER MAS RAPIDO, Y ESTOY REVISANDO EL NOLOGGING PERO NO LE ENTIENDO COMO HACER.
ALGUIE PODRIA AYUDARMEN
TAMBIEN
CREATE OR REPLACE PROCEDURE MIGRAC_FTRD10K_CAT_PP_HIST1
IS
varCat_PPHH number;
varFecTrans date;
varCatPP number;
varIDTransaccion number;
varIDPer_PKY con_transaccion.transaccion_id%type;---number;
varNomVen varchar2(250);
varNroPre number;
varResTransf varchAr2(50);
varNroNot varchar2(2);
varTipMov varchar2(2);
varPorDer number(5,2);
varFecIns date;
--cont numeric;
---varFecDesde date; -----variable para fecha hasta
varFecMoviento date;
--VarCount numeric;
varNumPredio number;
varFecha1 date;
varFecha2 date;
--varFecha3 date;
---varFechaAux date;
varFecValantes date;
auxCadFech varchar2(30);
auxCont numeric;
segundos numeric;
--Segundos1 numeric;
--auxfech date; ----varible para fecha hasta
--varFecDesde date; -----variable para fecha hasta
BEGIN
--- cont:=0;
auxCont:=0;
varFecMoviento:=sysdate;
---VarCount:=1;
DECLARE CURSOR datos_predio
IS
----sentecia para sacar todos los predios
SELECT DISTINCT(FT.TDNROPRE) from SGM.FTRD10K FT;
cursor DATOS_CAT_PP_HIST(pred numeric)
is
-----permite sacar los datos de la tabla par insertar en la tabla cat_propie_pred_hist
select
ft.tdfectrf,
cat.prop_predio_id,
ct.transaccion_id,
per.per_id_pky,
ft.tdnomven,
ft.tdnropre,
ft.tdrestrf,
ft.tdnronot,
ft.tdtipmov,
ft.tdporder,
ft.tdfectrf
from ftrd10k_ftrd10k1 ft JOIN con_transaccion_prueba_v1 ct ON
ft.tdfecmov=ct.fecha and ft.tdnropre=pred JOIN per_persona per ON
ft.tdnomven=per.denominacion and per.num_identificacion is null join cat_propie_pred cat on cat.num_predio=pred
group by cat.prop_predio_id,ft.tdfectrf,ct.transaccion_id,per.per_id_pky,ft.tdnomven,ft.tdnropre , ft.tdrestrf,
ft.tdnronot,
ft.tdtipmov,
ft.tdporder,
ft.tdfecmov
order by ft.tdfectrf ASC;
BEGIN
OPEN datos_predio;
FOR i IN 1..800000 LOOP
FETCH datos_predio INTO varNroPre;
EXIT WHEN datos_predio%NOTFOUND;
open DATOS_CAT_PP_HIST(varNroPre);
for i in 1..800000 loop
fetch DATOS_CAT_PP_HIST INTO varFecTrans,varCatPP,varIDTransaccion,varIDPer_PKY,varNomVen,varNumPredio,varResTransf,varNroNot,varTipMov,varPorDer,varFecIns;
exit when DATOS_CAT_PP_HIST%NOTFOUND;
auxCadFech:=to_char(varFecTrans,'yyyy');
if(auxCont=0) then
if (auxCadFech is null) then
varFecha1:=null;
varFecha2:=null;
else
varFecha1:=to_date('01/01/'||to_char(varFecTrans,'yyyy')||' 00:00:01','dd/mm/yyyy hh24:mi:ss');-----para la fecha desde
segundos:=1;
varFecha2:=to_date(to_char(varFecTrans,'dd')||'/'||to_char(varFecTrans,'mm')||'/'||to_char(varFecTrans,'yyyy'),'dd/mm/yyyy'); ----fecha hasta o fecha original
end if;
if(varFecha1 is not null )then
varFecValantes:=varFecha1;
end if;
else ---para el auxCont
-----------------------------------------------------------------
if(varFecha1 is not null )then
varFecValantes:=varFecha1;
end if;
if (varFecValantes is null) then
if(varFecha2 is null )then
segundos:=segundos+1;
varFecha1:=null;
else
segundos:=segundos+1;
varFecha1:=fecha_mas_segundos_fun123(varFecha2,segundos);
end if;
else
if(varFecha2 is null ) then
segundos:=segundos+1;
varFecha1:=null;
else
if(trunc(varFecha2)=trunc(varFecValantes)) then
segundos:=segundos+1;
varFecha1:=fecha_mas_segundos_fun123(varFecha2,segundos);
else
segundos:=1;
varFecha1:=fecha_mas_segundos_fun123(varFecha2,segundos);
end if;
end if;
segundos:=segundos+1;
end if;
-----------------------------------------------------------------
/* if(cont=0) then
dia:=(to_char(varFecTrans,'dd'));
mes:=to_char(varFecTrans,'mm');
anio:=to_char(varFecTrans,'yyyy');
hora :=to_char(varFecTrans,'hh24');
minit := to_char(varFecTrans,'mi');
seg :=to_char(varFecTrans,'ss');
auxfech := to_date(to_char(dia)||'/'||to_char(mes)||'/'||to_char(anio)||' '||'00:00:01','dd/mm/yyyy hh24:mi:ss');
varSegundos:=1;
cont:=cont+1;
else
if (trunc(auxfech)=trunc(varFecTrans)) then
varSegundos :=varSegundos+1;
auxfech :=fecha_mas_segundos_fun123(varFecTrans,varSegundos);
else
varSegundos :=1;
auxfech :=fecha_mas_segundos_fun123(varFecTrans,varSegundos);
end if;
cont:=cont+1;
end if; */
auxCont:=auxCont+1;
end if; ----para el incremento del contador auxCont
select cat_pp_hist_sec.nextval into varCat_PPHH from dual ;
insert into CAT_PROPIE_PRE_HIST_PRUEBA (PROP_PREDIO_ID_HIST,PROP_PREDIO_ID,PERSONA_ID,NUM_PREDIO,TRANSACCION_ID,PORCEN_DDAA,NOTARIA,FEC_INSCRIPCION,FEC_MODREGISTRO,USUARIO,ESTADO,FEC_RIGE_DESDE,FEC_RIGE_HASTA)
values
(
varCat_PPHH,varCatPP,varIDPer_PKY,varNumPredio,varIDTransaccion,varPorDer,varNroNot,varFecIns,varFecMoviento,varResTransf,varTipMov,varFecha1,varFecTrans);
commit;
end loop;
close DATOS_CAT_PP_HIST;
END LOOP;
CLOSE datos_predio;
-- VarCount:=VarCount+1;
END;
END;
YA LE PUESE EN EL FOR 800000 PERO PORQUE ESTA 800000000 TODAVIA SIQGUE LENTO
TAMBIEN TENGO UNA DUDA SEGUN LO QUE HE LEIDO DICE QUE EL CURSOR TERMINA CUANDO YA NO EXISTE REGISTROS Y LOS QUE ESTA EN EL FOR 800000000 DEJEN DE FUNCIONAR, ES VERDAD ESO
EXISTE DE LAGUNA FORMA DE HACER MAS RAPIDO, Y ESTOY REVISANDO EL NOLOGGING PERO NO LE ENTIENDO COMO HACER.
ALGUIE PODRIA AYUDARMEN
TAMBIEN