create or replace procedure printResult is cursor cur_select is select tname from tab; begin for cur in cur_select loop dbms_output.put_line(cur.tname); end loop;
end printResult;
不好意思,我是想实现如果select 有结果(一个,多个均可),我将执行一段代码,如果select 没有结果执行另外的代码,问题是我不知道怎么写这个判断有无的语句,我写了if sql%found then 不好用(我的数据库中有符合条件的记录,可是没有执行if sql%found then 下面的代码),我该怎么写啊???
create or replace procedure ex_cursor_fetch is cursor cursorSubTerm is 你的select语句; begin open cursorFullTerm; if cursorFullTerm%notfound then ....... --未找到记录的处理内容; else ......... --找到记录的处理内容; end if; exception ..... --发生异常的处理内容 end;
cursor cur_select is
select tname from tab;
begin
for cur in cur_select
loop
dbms_output.put_line(cur.tname);
end loop;
end printResult;
cursor cursorSubTerm is 你的select语句;
begin
open cursorFullTerm;
if cursorFullTerm%notfound then
....... --未找到记录的处理内容;
else
......... --找到记录的处理内容;
end if;
exception
..... --发生异常的处理内容
end;
close cursorFullTerm;