Como são muitos dados, tenta fazer a carga utilizando bulk collect. Segue
um exemplo, mas tem que testar.
CREATE OR REPLACE
PROCEDURE TESTE_BULK IS
cursor c_fatura is
select cd_servico
,nr_ano_fatura
,cd_doccobr
,nr_fatura
,vl_vig_fatura
,dt_emis_fatura
,dt_venc_fatura
,cd_sitcobr
,cd_ocor_banc_fatura
,dt_ocor_fatura
,cd_ccfgv
,dt_ocor_man_fatura
,dt_pago_cli_fatura
,ds_status_cobranca
,vl_pago_fatura
,cd_cgc_cpf_cliente
,f_recupera_nome_cliente(cd_servico,nr_ano_fatura,cd_doccobr,nr_fatura)
nm_cli_endcobr
,nr_trx_number_erp
from fatura
order by dt_venc_fatura;
--
type cd_servico is table of
analise_inadimplencia_part.cd_servico%type;
type nr_ano_fatura is table of
analise_inadimplencia_part.nr_ano_fatura%type;
type cd_doccobr is table of
analise_inadimplencia_part.cd_doccobr%type;
type nr_fatura is table of
analise_inadimplencia_part.nr_fatura%type;
type vl_vig_fatura is table of
analise_inadimplencia_part.vl_vig_fatura%type;
type dt_emis_fatura is table of
analise_inadimplencia_part.dt_emis_fatura%type;
type dt_venc_fatura is table of
analise_inadimplencia_part.dt_venc_fatura%type;
type cd_sitcobr is table of
analise_inadimplencia_part.cd_sitcobr%type;
type cd_ocor_banc_fatura is table of
analise_inadimplencia_part.cd_ocor_banc_fatura%type;
type dt_ocor_fatura is table of
analise_inadimplencia_part.dt_ocor_fatura%type;
type cd_ccfgv is table of
analise_inadimplencia_part.cd_ccfgv%type;
type dt_ocor_man_fatura is table of
analise_inadimplencia_part.dt_ocor_man_fatura%type;
type dt_pago_cli_fatura is table of
analise_inadimplencia_part.dt_pago_cli_fatura%type;
type ds_status_cobranca is table of
analise_inadimplencia_part.ds_status_cobranca%type;
type vl_pago_fatura is table of
analise_inadimplencia_part.vl_pago_fatura%type;
type cnpj_cpf_cliente is table of
analise_inadimplencia_part.cnpj_cpf_cliente%type;
type nm_cli_endcobr is table of
analise_inadimplencia_part.nm_cli_endcobr%type;
type nr_trx_number_erp is table of
analise_inadimplencia_part.nr_trx_number_erp%type;
--
type nr_processo is table of number;
type dt_referencia is table of date;
type dt_ini_per is table of date;
type dt_fim_per is table of date;
type cd_ccfgv_nivel1 is table of varchar2(3);
type cd_unidade is table of number(3);
--
r_cd_servico cd_servico;
r_nr_ano_fatura nr_ano_fatura;
r_cd_doccobr cd_doccobr;
r_nr_fatura nr_fatura;
r_vl_vig_fatura vl_vig_fatura;
r_dt_emis_fatura dt_emis_fatura;
r_dt_venc_fatura dt_venc_fatura;
r_cd_sitcobr cd_sitcobr;
r_cd_ocor_banc_fatura cd_ocor_banc_fatura;
r_dt_ocor_fatura dt_ocor_fatura;
r_cd_ccfgv cd_ccfgv;
r_dt_ocor_man_fatura dt_ocor_man_fatura;
r_dt_pago_cli_fatura dt_pago_cli_fatura;
r_ds_status_cobranca ds_status_cobranca;
r_vl_pago_fatura vl_pago_fatura;
r_cnpj_cpf_cliente cnpj_cpf_cliente;
r_nm_cli_endcobr nm_cli_endcobr;
r_nr_trx_number_erp nr_trx_number_erp;
--
r_nr_processo nr_processo;
r_dt_referencia dt_referencia;
r_dt_ini_per dt_ini_per;
r_dt_fim_per dt_fim_per;
r_cd_ccfgv_nivel1 cd_ccfgv_nivel1;
r_cd_unidade cd_unidade;
--
v_cd_unidade unidade_analise_inadimplencia.cd_unidade%type;
Begin
execute immediate 'truncate table fatura_bulk reuse storage';
--
Begin
open c_fatura;
loop
fetch c_fatura
bulk collect
into r_cd_servico
,r_nr_ano_fatura
,r_cd_doccobr
,r_nr_fatura
,r_vl_vig_fatura
,r_dt_emis_fatura
,r_dt_venc_fatura
,r_cd_sitcobr
,r_cd_ocor_banc_fatura
,r_dt_ocor_fatura
,r_cd_ccfgv
,r_dt_ocor_man_fatura
,r_dt_pago_cli_fatura
,r_ds_status_cobranca
,r_vl_pago_fatura
,r_cnpj_cpf_cliente
,r_nm_cli_endcobr
,r_nr_trx_number_erp
limit 1000;
begin
forall i in r_nr_fatura.first .. r_nr_fatura.last
insert into fatura_bulk
( cd_servico, nr_ano_fatura, cd_doccobr, nr_fatura
,vl_vig_fatura, dt_emis_fatura, dt_venc_fatura
,cd_sitcobr, cd_ocor_banc_fatura, dt_ocor_fatura
,cd_ccfgv, dt_ocor_man_fatura, dt_pago_cli_fatura
,ds_status_cobranca, vl_pago_fatura, cnpj_cpf_cliente
,nm_cli_endcobr,nr_trx_number_erp )
values (
r_cd_servico(i),r_nr_ano_fatura(i),r_cd_doccobr(i),r_nr_fatura(i)
,r_vl_vig_fatura(i), r_dt_emis_fatura(i),
r_dt_venc_fatura(i)
,r_cd_sitcobr(i), r_cd_ocor_banc_fatura(i),
r_dt_ocor_fatura(i)
,r_cd_ccfgv(i), r_dt_ocor_man_fatura(i),
r_dt_pago_cli_fatura(i)
,r_ds_status_cobranca(i), r_vl_pago_fatura(i),
r_cnpj_cpf_cliente(i)
,r_nm_cli_endcobr(i),r_nr_trx_number_erp(i) );
exception
when others then dbms_output.put_line ('Erro carga fatura
'||sqlerrm);
return;
end;
exit when c_fatura%notfound;
end loop;
commit;
close c_fatura;
dbms_output.put_line('Fim Carga fatura '||to_char(sysdate,'dd/mm/yyyy
hh24:mi:ss'));
exception
when others then
dbms_output.put_line('Erro na Carga fatura '||sqlerrm);
return;
end;
End;
/
Em 19 de março de 2010 12:41, Jose Luis Ramos
<[email protected]>escreveu:
>
>
> Pessoal, preciso de uma ajuda em um PL/SQL que, segundo meus cálculosvai
> demorar 3 dias para rodar. É inviável. O processo é uma migração de dados
> entre dois sistemas. Eu carrego primeiramente a tabela CARGA_PORTABILIDADE
> (através do SQL*LOADER) e depois em cima desta tabela eu executo um PL/SQL
> para preencher duas outras tabelas pertencentes ao sistema para o qual os
> dados estão sendo migrados (SERV_PORTABILIDADE_TMP E
> SERV_PORTABILIDADE_CRIADO_TMP). Ja fiz alguns ajustes que melhorarm um
> pouco, mas não muito. Alterei os seguintes parâmetros:
>
> CUROR_SHARING=SIMILAR
> OPTIMIZER_INDEX_CACHING=70
> OPTIMIZER_INDEX_COST_ADJ=30
> PGA_AGGREGATE_TARGET=5g
> OPTIMIZER_MODE=ALL_ROWSS (esta o default)
> CURSOR_SPACE_FOR_TIME=TRUE
> SESSION_CACHED_CURSOR=500
>
> além disse coloquei os índices em tablespace separada das tabelas e criei
> um
> JOB que recalcula as estatísticas para as tabelas deste SCHEMA para rodar
> de
> 5 em 5 minutos. O Servisor é um HP que tem 60GB de RAM , dois processadores
> dual core e 4 discos de 300GB em RAID 0+1.
>
> O código do PL/SQL qu executo está abaixo. O SQL*LOADER não é o gargalo.
> Roda em alguns minutos. O total de registros que devem ser processados pelo
> PL/SQL é de 4milhões de linhas. Se alguém puder me dar alguma dica eu
> agradeço muito. Abraços.
>
> CREATE OR REPLACE procedure PROC_PORTABILIDADE
> is
> CURSOR C_CARGA IS
> SELECT * FROM CARGA_PORTABILIDADE;
> CURSOR C_PORT IS
> SELECT * FROM SERV_PORTABILIDADE_TMP;
> v_count NUMBER;
> sql1 varchar2(255) := 11;
> REG_CARGA C_CARGA%ROWTYPE;
> REG_PORT C_PORT%ROWTYPE;
> t1 varchar2(1600) := '';
> t2 varchar2(1600) := '';
> BEGIN
> sql1 := 'TRUNCATE TABLE SERV_PORTABILIDADE_TMP';
> execute immediate sql1;
> sql1:= 'TRUNCATE TABLE SERV_PORTABILIDADE_CRIADO_TMP';
> execute immediate sql1;
> OPEN C_CARGA;
> LOOP
> FETCH C_CARGA INTO REG_CARGA;
> EXIT WHEN C_CARGA%NOTFOUND;
> OPEN C_PORT;
> LOOP
> FETCH C_PORT INTO REG_PORT;
> V_COUNT := 0;
> SELECT /*+ index(carga_portabilidade IDX_NTL_CARGA_PORTAB_TMP)
> index(SERV_PORTABILIDADE_TMP IDX_NTL_SERV_PORTAB_TMP */
> COUNT(1) INTO V_COUNT FROM SERV_PORTABILIDADE_TMP
> WHERE REG_CARGA.NTL = SERV_PORTABILIDADE_TMP.NTL;
> IF (REG_CARGA.NTL IS NOT NULL) AND (V_COUNT IS NULL OR V_COUNT = 0)
> THEN
> INSERT INTO SERV_PORTABILIDADE_TMP
> VALUES(SERV_PORTABILIDADE_SEQ_TMP.NEXTVAL, 0,
> REG_CARGA.DATA_CRIACAO, REG_CARGA.ULTIMA_ATUALIZACAO,
> REG_CARGA.ULTIMA_OPERACAO,
> REG_CARGA.NTL, REG_CARGA.OPC, REG_CARGA.rn1,
> REG_CARGA.cnl, REG_CARGA.NUF, REG_CARGA.TPB, REG_CARGA.CPT, REG_CARGA.EIP,
> REG_CARGA.NUE, REG_CARGA.TBR, REG_CARGA.CRE);
> INSERT INTO SERV_PORTABILIDADE_CRIADO_TMP
> VALUES(SERV_PORTABILIDADE_SEQ_TMP.CURRVAL, REG_CARGA.SIGLA_ER,
> REG_CARGA.OBJ_SAIDA, REG_CARGA.DATA_CRIACAO,
> REG_CARGA.ULTIMA_ATUALIZACAO,
> REG_CARGA.ULTIMA_OPERACAO);
> ELSE IF REG_CARGA.NTL = REG_PORT.NTL THEN
> INSERT INTO SERV_PORTABILIDADE_CRIADO_TMP
> VALUES(REG_PORT.ID <http://reg_port.id/>, REG_CARGA.SIGLA_ER,
> REG_CARGA.OBJ_SAIDA,
> REG_PORT.DATA_CRIACAO, REG_PORT.ULTIMA_ATUALIZACAO,
> REG_PORT.ULTIMA_OPERACAO);
> t1 := REG_CARGA.Opc|| REG_CARGA.Rn1|| REG_CARGA.Cnl||
> REG_CARGA.Nuf|| REG_CARGA.Tpb|| REG_CARGA.Cpt|| REG_CARGA.Eip||
> REG_CARGA.Nue|| REG_CARG
> A.TBR|| REG_CARGA.Cre;
> t2 := REG_PORT.Opc || REG_PORT.Rn1 || REG_PORT.Cnl ||
> REG_PORT.Nuf || REG_PORT.Tpb || REG_PORT.Cpt || REG_PORT.Eip||
> REG_PORT.Nue|| REG_PORT.T
> BR|| REG_PORT.Cre;
> IF t1 <> t2 then
> INSERT INTO SERV_PORTABILIDADE_LOG
> VALUES(REG_PORT.ID <http://reg_port.id/>, REG_CARGA.NTL, REG_CARGA.OPC,
> REG_CARGA.rn1, REG_CARGA.cnl, REG_CARGA.NUF, REG_CARGA.TPB, REG_CARGA.CPT,
> REG_CARGA.EIP, REG_CARGA.NUE, REG_CARGA.TBR,
> REG_CARGA.CRE, REG_CARGA.SIGLA_ER, REG_CARGA.OBJ_SAIDA);
> END IF;
> END IF;
> END IF;
> EXIT WHEN C_PORT%NOTFOUND;
> END LOOP;
> COMMIT;
> CLOSE C_PORT;
> END LOOP;
> CLOSE C_CARGA;
> EXCEPTION
> WHEN DUP_VAL_ON_INDEX THEN
> NULL;
> WHEN OTHERS THEN
> NULL;
> END;
> /
>
> --
> Jose Luis Ramos Jr
> Campinas - SP
> Oracle OCP DBA 8i, 9i,10g
> Fone: 19-37056793
>
> [As partes desta mensagem que não continham texto foram removidas]
>
>
>
[As partes desta mensagem que não continham texto foram removidas]
------------------------------------
--------------------------------------------------------------------------------------------------------------------------
>Atenção! As mensagens do grupo ORACLE_BR são de acesso público e de inteira
>responsabilidade de seus remetentes.
Acesse: http://www.mail-archive.com/[email protected]/
--------------------------------------------------------------------------------------------------------------------------
>Apostilas » Dicas e Exemplos » Função » Mundo Oracle » Package » Procedure »
>Scripts » Tutoriais - O GRUPO ORACLE_BR TEM SEU PROPRIO ESPAÇO! VISITE:
>http://www.oraclebr.com.br/
------------------------------------------------------------------------------------------------------------------------
Links do Yahoo! Grupos
<*> Para visitar o site do seu grupo na web, acesse:
http://br.groups.yahoo.com/group/oracle_br/
<*> Para sair deste grupo, envie um e-mail para:
[email protected]
<*> O uso que você faz do Yahoo! Grupos está sujeito aos:
http://br.yahoo.com/info/utos.html