数据库

 首页 > 数据库 > MySql > plsql游标最后一行重复的问题

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

分享到:
【字体:
导读:
         摘要:plsql游标最后一行重复的问题 ...

plsql游标最后一行重复的问题
大家仔细看一下,下面第一个存储过程,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;



plsql游标最后一行重复的问题
分享到:
LINUX下安装Oracle后无法建监听
LINUX下安装Oracle后无法建监听 ***********************************************声明**********************************************  原创作品,出自 “深蓝的blog” 博客,欢迎转载,转载时请务必注明出处,否则追究版权法律责任。 表述有错误之处,请您留言或邮件(hyldba@163.com)指明,不胜感激。 本文转载必须...
Git在linux下的使用
Git在linux下的使用*初始化git仓库,使用git init命令  *添加文件到git仓库分两步: 1、使用git add filename   ;可分多次使用,添加多个文件到暂存区 2、使用git commit -m  “说明”  ;完成提交到分支 *查看工作区状态,使用git status 命令;如果提示有修改可使用git diff filename 查看修改内容 *HEAD指向当前...
  •         php迷,一个php技术的分享社区,专属您自己的技术摘抄本、收藏夹。
  • 在这里……