1)oracle procdure 内异常处理
for num in 1..total loop
begin
strsql := 'select ssid from (select temp.sp_id as ssid, rownum as ssnum
from tempInfo temp) where ssnum='|| num;
execute immediate strsql into tempspid;
strsql := 'update tempInfo set black_count =
(select count(black.id) as blackcount
from nm_black_and_object black where black.sp_id =' || tempspid || ')
where sp_id=' || tempspid;
execute immediate strsql;
table_name := 'NM_NET_USER_'||tempspid;
dbms_output.put_line(table_name);
strsql := 'update tempInfo set white_count =
(select count(distinct us.mdn) from NM_NET_USER_' || tempspid || ' us
where us.status in (1,2,3))
where sp_id=' || tempspid;
execute immediate strsql;--此处可能引发 试图不存在异常 ,但是不该影响下面业务处理
end ;
end loop;
--办法一 通过一次select 判断试图是否存在 ,如果存在则执行
strsql := 'select count(*) from user_tables where table_name='''||table_name||'''';
execute immediate strsql INTO counter ;
IF counter > 0 THEN
strsql := 'update tempInfo set white_count =
(select count(distinct us.mdn) from NM_NET_USER_' || tempspid || ' us
where us.status in (1,2,3))
where sp_id=' || tempspid;
execute immediate strsql;--此处可能引发 试图不存在异常 ,但是不该影响下面业务处理
END IF ;
---办法2 通过EXCEPTION
strsql := 'update tempInfo set white_count =
(select count(distinct us.mdn) from NM_NET_USER_' || tempspid || ' us
where us.status in (1,2,3))
where sp_id=' || tempspid;
execute immediate strsql;--此处可能引发 试图不存在异常 ,但是不该影响下面业务处理
exception
when others then null ;
Oracle Procedure 异常处理
本文介绍在Oracle Procedure中如何处理潜在的异常情况,特别是针对视图不存在的问题提供了两种解决方案:一是通过预先检查视图的存在性来避免异常;二是利用EXCEPTION块来捕获并处理异常,确保后续业务逻辑不受影响。
1973

被折叠的 条评论
为什么被折叠?



