原本的存储过程太长了,截取出来,大家帮忙看下到底是哪儿错了。。以前没用过游标,现在我每次遍历游标都有这个我问题。就算游标没有数据,不会在exit notfound 那里停,非要进去走一遍才好不知道该怎么办了。
open sel_dl_id for select yingyetingid from yingyeting where yingyetingid not in(select yingyetingid from ClientOnLine where to_char(VisitStartDate)=to_char(sysdate));
     loop 
     exit when sel_dl_id%notfound;
          fetch sel_dl_id into yingyetingid2;
          insert into ExceptionInfo values(seq_exceptioninfo.nextval,dl_id,sysdate,yingyetingid2);
     end loop;谢谢大家了

解决方案 »

  1.   

    你的语句是先进循环后判断,试下先判断后进循环的语句吧open sel_dl_id for select yingyetingid from yingyeting where yingyetingid not in(select yingyetingid from ClientOnLine where to_char(VisitStartDate)=to_char(sysdate)); 
        while sel_dl_id%notfound loop 
              fetch sel_dl_id into yingyetingid2; 
              insert into ExceptionInfo values    (seq_exceptioninfo.nextval,dl_id,sysdate,yingyetingid2); 
    end loop; 
      

  2.   

    open sel_dl_id for select yingyetingid from yingyeting where yingyetingid not in(select yingyetingid from ClientOnLine where to_char(VisitStartDate)=to_char(sysdate)); 
        loop 
        
              fetch sel_dl_id into yingyetingid2; 
    exit when sel_dl_id%notfound; ---这句放这里来
              insert into ExceptionInfo values(seq_exceptioninfo.nextval,dl_id,sysdate,yingyetingid2); 
        end loop; 
      

  3.   

    open sel_dl_id for select yingyetingid from yingyeting where yingyetingid not in(select yingyetingid from ClientOnLine where to_char(VisitStartDate)=to_char(sysdate)); 
        loop 
        fetch sel_dl_id into yingyetingid2;--注意位置顺序
        exit when sel_dl_id%notfound; 
               
              insert into ExceptionInfo values(seq_exceptioninfo.nextval,dl_id,sysdate,yingyetingid2); 
        end loop; 
      

  4.   

    应该是在FETCH后在写EXIT WHEN........
      

  5.   

    游标是要先fetch, 才能使用游标的属性的。2楼的还没有fetch就用%notfound了,语义上就有问题。