How to declare a cursor after the begin section of an Oracle PL/SQL procedure -
i new in oracle pl/sql. trying write procedure first data column in table , assign variable. each row/value in result, perform query , loop through result of new query , perform various inserts , updates. after go outer loop , continue sequence. attempt follows:
create or replace procedure cmsadmin.proc_rfc_upd_new_mrsp ecode number; emesg varchar2(200); cursor y (select distinct cod_unicom fcode rfc_upd_new_mrsp_pool); begin t in y loop cursor x ( select distinct s.nif premise,a.cod_unicom reading, a.cod_lect_area area sumcon s, lect_areas a.cod_unicom = t.fcode , s.num_sum in (select num_sum rfc_upd_new_mrsp_pool cod_unicom = t.fcode) ); met in x loop /* store record trace*/ insert rfc_upd_new_mrsp(nif, cod_unicom,cod_lect_area, usuario, f_actual, programa) values (met.premise, met.reading, met.area, user, sysdate,'rfc_mrsp_fpl'); update fincas_per_lect fp set fp.num_mrsp = met.reading, fp.aol_fin=0, fp.num_itin =0, fp.usuario = user, fp.programa = 'rfc_mrsp_fpl', fp.f_actual = sysdate fp.nif=met.premise; update apmedida_ap fp set fp.num_mrsp = met.reading, fp.usuario = user, fp.programa = 'rfc_mrsp_fpl', fp.f_actual = sysdate fp.nif_apa = met.premise; update fincas fp set area_lect = met.area, fp.usuario = user, fp.programa = 'rfc_mrsp_fpl', fp.f_actual = sysdate nif = met.premise; end loop; end loop; commit; dbms_output.put_line('the procedure proc_rfc_upd_new_mrsp executed successfully'); exception when others ecode := sqlcode; emesg := sqlerrm; dbms_output.put_line('the procedure proc_rfc_upd_new_mrsp fail folowing error '|| to_char(ecode) || ' , error message: ' || emesg); null; end proc_rfc_upd_new_mrsp;
as can see have cursor after loop inside begin
. allowed? script doesn't work expected. problem? appreciate help
to this, you'd need declare new block:
for t in y loop declare cursor x ( select distinct s.nif premise,a.cod_unicom reading, a.cod_lect_area area sumcon s, lect_areas a.cod_unicom = t.fcode , s.num_sum in (select num_sum rfc_upd_new_mrsp_pool cod_unicom = t.fcode) ); begin met in x loop ... end loop; end;
however, don't quite see why can't declare cursor along cursor y, defined parameter:
cursor x (p_fcode rfc_upd_new_mrsp_pool.cod_unicom%type) ( select distinct s.nif premise,a.cod_unicom reading, a.cod_lect_area area sumcon s, lect_areas a.cod_unicom = p_fcode , s.num_sum in (select num_sum rfc_upd_new_mrsp_pool cod_unicom = p_fcode) );
you reference cursor thusly:
for met in x(t.fcode) loop
Comments
Post a Comment