我是plsql的初学者。下面的代码运行时没有任何编译错误,但notFoundException没有被调用。任何帮助将被appriciated。异常没有在plsql中调用
declare
abc exception;
notFoundException exception;
cursor c1(dd number) is select first_name from employees where salary = dd;
begin
for i in c1(&t)
loop
if(c1%rowcount!=1) then
raise abc;
elsif(c1%notfound) then
raise notFoundException;
else
dbms_output.put_line(i.first_name);
end if;
end loop;
Exception
when abc then
dbms_output.put_line('abc');
insert into messages values('too many rows exception');
when notFoundException then
dbms_output.put_line('notFoundException');
insert into messages values('Nobody with this salary : ');
end;
/
有很多与此代码的问题。如果查询不返回任何行,则不会进入循环。 'c1%rowcount'是到目前为止获取的行数,而不是将获取多少行。在这种情况下'c1%notfound'永远不会是'true'。我猜这是一项家庭作业,我不确定你实际上想要完成什么。也许你想做一个'select into',然后处理'no_data_found'和'too_many_rows'执行选项。 –