1

嗨,伙计们,我有一个 pl/sql 语句,它应该通过游标从一个表中获取数据到另一个表,但是有些字段是空的,我想这就是它退出该行的原因

exit when cursor%not found;

我用谷歌搜索了一下,我看到了在 fetch 语句之后使用该行的建议,但是当你有两个游标但在 Mycase 我有一个游标时似乎就是这种情况。请有人帮我调整这个查询

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;
4

1 回答 1

2

自 Oracle 8 以来,不再需要显式游标(恕我直言)。我将重写您的代码以在 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;
于 2012-07-25T20:11:44.017 回答