|
Boa tarde Amigos, espero que possam me ajudar, eu estava usando a
versão 8.3.7 e essa stored procedure funcionava normalmente, mais agora
na versão 8.3.10 quando chega no primeiro FOR IN ele não entra no loop,
como se não tivesse registros (mais tem!) segue o código abaixo: CREATE OR REPLACE FUNCTION "public"."f_rodar_reportagem" (integer, integer) RETURNS boolean AS $body$ DECLARE pIDREPESP ALIAS FOR $1; pIDPROG ALIAS FOR $2; REC_N1 RECORD; REC_N2 RECORD; REC_N3 RECORD; TOTALSEGS INTEGER; QTDREG INTEGER; TEMPOMIN TIMESTAMP(0); INI_P TIMESTAMP(0); FIM_P TIMESTAMP(0); CUSTO_P NUMERIC(10,2); TEMPOPROP_P NUMERIC(14,4); VALORPROP_P NUMERIC(14,4); BEGIN -- Retornar True se o código for executado sem erros, False caso ocorra alguma exception -- Pega o custo do programa CUSTO_P := custo30/30 from cli_progsmidia where idprog = pIDPROG; FOR REC_N1 IN select * from rep_eventon1 where idrepesportesmt = pIDREPESP and idprog = pIDPROG LOOP insert into testerodar values (REC_N1.idrep_eventon1); -- testando se chega aqui update rep_eventon1 set valor_total = (CUSTO_P / 30) * REC_N1.intervalo where idrep_eventon1 = REC_N1.idrep_eventon1; TEMPOMIN := REC_N1.ini; TOTALSEGS := REC_N1.intervalo; FOR Segundos IN 0..TOTALSEGS LOOP INI_P := TEMPOMIN + (Segundos || ' second')::interval; FIM_P := INI_P + interval '1 second'; FOR REC_N2 IN select * from reportagemdadosn2 where idrep_eventon1 = REC_N1.idrep_eventon1 and ini <= INI_P and fim >= FIM_P LOOP QTDREG = count(*) from reportagemdadosn2 where idrep_eventon1 = REC_N1.idrep_eventon1 and ini <= INI_P and fim >= FIM_P; TEMPOPROP_P := REC_N2.tmp_prop + (1.0 / QTDREG); VALORPROP_P := (CUSTO_P / 30) * TEMPOPROP_P; update reportagemdadosn2 set tmp_prop = TEMPOPROP_P, valor_prop = VALORPROP_P, valor_total = (CUSTO_P / 30) * REC_N2.intervalo where idreportagemdadosn2 = REC_N2.idreportagemdadosn2; END LOOP; FOR REC_N3 IN select * from reportagemdadosn3 where idrep_eventon1 = REC_N1.idrep_eventon1 and ini <= INI_P and fim >= FIM_P LOOP QTDREG = count(*) from reportagemdadosn3 where idrep_eventon1 = REC_N1.idrep_eventon1 and ini <= INI_P and fim >= FIM_P; TEMPOPROP_P := REC_N3.tmp_prop + (1.0 / QTDREG); VALORPROP_P := (CUSTO_P / 30) * TEMPOPROP_P; update reportagemdadosn3 set tmp_prop = TEMPOPROP_P, valor_prop = VALORPROP_P, valor_total = (CUSTO_P / 30) * REC_N3.intervalo where idreportagemdadosn3 = REC_N3.idreportagemdadosn3; END LOOP; END LOOP; -- loop for END LOOP; -- nível1 RETURN true; EXCEPTION WHEN OTHERS THEN RETURN false; END; $body$ LANGUAGE 'plpgsql' VOLATILE CALLED ON NULL INPUT SECURITY INVOKER COST 100; --
|
_______________________________________________ pgbr-geral mailing list [email protected] https://listas.postgresql.org.br/cgi-bin/mailman/listinfo/pgbr-geral

