Stanley Mungai
Stanley Mungai

Reputation: 4150

Exit when Cursor%not found Issue

Hi guys I have a pl/sql statement which is supposed to fetch data from one table to another through a cursor but some fields are empty and am thinking that is why it is exiting the line

exit when cursor%not found;

I have googled around and I have seen the suggestion to use the line after fetch statement but that seems to be the case when You have two cursors but in Mycase I have one cursor. Please some one help me tune up this query

CREATE OR REPLACE procedure TBAADM.MIGR_EIT
AS
CURSOR cur_eit  IS SELECT entity_id, nrml_accrued_amount_cr,nrml_accrued_amount_dr,   nrml_booked_amount_cr, nrml_booked_amount_dr, nrml_interest_amount_cr,
nrml_interest_amount_dr,
next_int_run_date_cr ,next_int_run_date_dr ,interest_calc_upto_date_cr,   interest_calc_upto_date_dr,xfer_min_bal
,xfer_min_bal_date, booked_upto_date_cr,booked_upto_date_dr FROM TBAADM.eit_temp  ;
tempeit1  TBAADM.EIT%ROWTYPE;
number_of_rows_updated number;
BEGIN
number_of_rows_updated:=0;

update tbaadm.eit_temp set entity_id=(select gam.acid from tbaadm.gam where gam.foracid=eit_temp.act_num);

OPEN cur_eit;

LOOP
FETCH cur_eit INTO  tempeit1.entity_id,tempeit1.nrml_accrued_amount_cr,tempeit1.nrml_accrued_amount_dr,tempeit1    .nrml_booked_amount_cr,tempeit1.nrml_booked_amount_dr,
tempeit1.nrml_interest_amount_cr, tempeit1.nrml_interest_amount_dr,
tempeit1.next_int_run_date_cr ,tempeit1.next_int_run_date_dr  ,tempeit1.interest_calc_upto_date_cr,  tempeit1.interest_calc_upto_date_dr,tempeit1.xfer_min_bal
,tempeit1.xfer_min_bal_date, tempeit1.booked_upto_date_cr,tempeit1.booked_upto_date_dr;
exit when cur_eit%notfound;

Upvotes: 1

Views: 4192

Answers (1)

GWu
GWu

Reputation: 2787

Explicit cursors are not required (and IMHO advisible) anymore since Oracle 8. I'd rewrite your code to use an implicit cursor in a FOR ... LOOP:

CREATE OR REPLACE PROCEDURE tbaadm.migr_eit
AS
  number_of_rows_updated   NUMBER;
BEGIN
  number_of_rows_updated := 0;

  UPDATE tbaadm.eit_temp
     SET entity_id =
           (SELECT gam.acid
              FROM tbaadm.gam
             WHERE gam.foracid = eit_temp.act_num);

  FOR tempeit1 IN (SELECT entity_id
                         ,nrml_accrued_amount_cr
                         ,nrml_accrued_amount_dr
                         ,nrml_booked_amount_cr
                         ,nrml_booked_amount_dr
                         ,nrml_interest_amount_cr
                         ,nrml_interest_amount_dr
                         ,next_int_run_date_cr
                         ,next_int_run_date_dr
                         ,interest_calc_upto_date_cr
                         ,interest_calc_upto_date_dr
                         ,xfer_min_bal
                         ,xfer_min_bal_date
                         ,booked_upto_date_cr
                         ,booked_upto_date_dr
                     FROM tbaadm.eit_temp)
  LOOP
    /* do what ever you need to do with 
      tempeit1.entity_id,tempeit1.nrml_accrued_amount_cr,tempeit1.nrml_accrued_amount_dr,tempeit1    .nrml_booked_amount_cr,tempeit1.nrml_booked_amount_dr,
      tempeit1.nrml_interest_amount_cr, tempeit1.nrml_interest_amount_dr,
      tempeit1.next_int_run_date_cr ,tempeit1.next_int_run_date_dr  ,tempeit1.interest_calc_upto_date_cr,  tempeit1.interest_calc_upto_date_dr,tempeit1.xfer_min_bal
      ,tempeit1.xfer_min_bal_date, tempeit1.booked_upto_date_cr,tempeit1.booked_upto_date_dr;
    */
    NULL; -- do something useful
  END LOOP;

Upvotes: 2

Related Questions