Oracle判断数据是否存在(使用游标判断需要注意的问题)

1.使用select into

begin
  select dno into v_dno from tbl where xxx.
exception
  when no_data_found then
  --无数据
end;

  

2.游标fetch

open mycursor;
fetch mycursor into rec;
  if mycursor%notfound then
    --无数据
  end if;
close mycursor;

3.游标%rowcount属性判断

open mycursor;
  if mycursor%rowcount =0 then
    --无数据
  end if;
 close mycursor;

注意:打开游标之后不fetch,就判断游标%notfound是不行的。不论有没有数据都会返回true。

posted @ 2013-11-19 17:36  烟花易冷丶人心易凉  阅读(3048)  评论(0编辑  收藏  举报