Exception捕捉异常处理

yhcustc 2007-08-14 10:51:53
我的问题如下,请求大家帮忙
FOR i IN (1..5) LOOP
如果中间产生异常如何继续循环,而不是碰到异常就退出?
END LOOP;
--------实际应用代码功能如下------------------
declare
str_sql varchar2(2000);
cursor get_obj is
select object_type, object_name from USER_OBJECTS
where status = 'INVALID'
and object_type in('PACKAGE BODY','VIEW');
begin
for rec_ in get_obj loop
if (rec_.object_type = 'VIEW') then
str_sql := 'ALTER VIEW "'|| rec_.object_name ||'" COMPILE';
else
str_sql := 'ALTER PACKAGE "'|| rec_.object_name ||'" COMPILE BODY';
end if;
execute immediate str_sql;
---本来我想把Exception放到这个位置的,结果执行时就是出错
end loop;
EXCEPTION WHEN OTHERS THEN
--放在这不出错但不是我想要的效果,只要中间有一个异常整体
--结束了,我是想要碰到异常继续下一个循环而不是退出.
dbms_output.put_line(sqlerrm);
end;
...全文
254 3 打赏 收藏 转发到动态 举报
写回复
用AI写文章
3 条回复
切换为时间正序
请发表友善的回复…
发表回复
yhcustc 2007-08-15
  • 打赏
  • 举报
回复
清高人指点一二。
intotheheart 2007-08-15
  • 打赏
  • 举报
回复
declare
str_sql varchar2(2000);
cursor get_obj is
select object_type, object_name from USER_OBJECTS
where status = 'INVALID'
and object_type in('PACKAGE BODY','VIEW');
begin
for rec_ in get_obj loop
if (rec_.object_type = 'VIEW') then
str_sql := 'ALTER VIEW "'|| rec_.object_name ||'" COMPILE';
else
str_sql := 'ALTER PACKAGE "'|| rec_.object_name ||'" COMPILE BODY';
end if;
begin
execute immediate str_sql;
exception
when .....
end;
---本来我想把Exception放到这个位置的,结果执行时就是出错
end loop;
EXCEPTION WHEN OTHERS THEN
--放在这不出错但不是我想要的效果,只要中间有一个异常整体
--结束了,我是想要碰到异常继续下一个循环而不是退出.
dbms_output.put_line(sqlerrm);
end
yhcustc 2007-08-15
  • 打赏
  • 举报
回复
问题解决了,揭帖了。
FOR i IN (1..5) LOOP
--用BEGIN EXCEPTION ENDJJ
END LOOP;

3,491

社区成员

发帖
与我相关
我的任务
社区描述
Oracle 高级技术相关讨论专区
社区管理员
  • 高级技术社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧