您的位置:首页 > 博客中心 > 数据库 >

plsql游标最后一行重复的问题

时间:2022-03-14 00:03

大家仔细看一下,下面第一个存储过程,test01,有没问题? 看似没问题,其实会造成重复行,test02将exit when的语句放到合适的位置上来。就不会出现最后一行重复打印的问题。

create or replace procedure test01 as   cursor cursor1 is     select * from v$session where rownum <= 5;   record1 cursor1%rowtype; begin   DBMS_OUTPUT.ENABLE(buffer_size => null);   open cursor1;   loop     fetch cursor1 into record1;     dbms_output.put_line(record1.sid);     exit when cursor1%notfound;   end loop;   close cursor1; end;
----------------------------------------------------------------------- create or replace procedure test02 as   cursor cursor1 is     select * from v$session where rownum <= 5;   record1 cursor1%rowtype; begin   DBMS_OUTPUT.ENABLE(buffer_size => null);   open cursor1;   loop     fetch cursor1 into record1;     exit when cursor1%notfound;     dbms_output.put_line(record1.sid);   end loop;   close cursor1; end;


热门排行

今日推荐

热门手游