在for循环内部处理异常,处理后程序继续执行
以下是测试程序,程序用来统计一个用户下的表信息,当表不存在时则说明在是另外一个用户的表,其中有几个表不存在。
表名都在 itsp_mapping.init_os_spec 中
-------------------------
create or replace procedure find_test
as
declare
v_tab_col_sum number(10);
v_sql varchar2(500);
tableid number(5):=10000;
not_exists exception;
pragma exception_init(not_exists,-942);
begin
for tname in (select coretablename from itsp_mapping.init_os_spec) loop --取出表名
tableid:=tableid+1;
begin
v_sql:='select count(1) from rmzh.'|| tname.coretablename;
execute immediate v_sql into v_tab_col_sum;
dbms_output.put_line(tableid||'---'||tname.coretablename||' --rmzh--- '||v_tab_col_sum);
exception
when not_exists then
if tname.coretablename in ('TB_INTF_RCGDXX','INTF_SYNC_TELANTHIS','INTF_ESBLOG','T_WORK_SHEET','CUT_WORKSHEET') then
dbms_output.put_line(tableid||'---'||tname.coretablename||' --not in both!!!!!!--- ');
else
v_sql:='select count(1) from infores.'||tname.coretablename;
execute immediate v_sql into v_tab_col_sum;
dbms_output.put_line(tableid||'---'||tname.coretablename||' --infores--- '||v_tab_col_sum);
end if;
end;
end loop;
end;
以下是测试程序,程序用来统计一个用户下的表信息,当表不存在时则说明在是另外一个用户的表,其中有几个表不存在。
表名都在 itsp_mapping.init_os_spec 中
-------------------------
create or replace procedure find_test
as
declare
v_tab_col_sum number(10);
v_sql varchar2(500);
tableid number(5):=10000;
not_exists exception;
pragma exception_init(not_exists,-942);
begin
for tname in (select coretablename from itsp_mapping.init_os_spec) loop --取出表名
tableid:=tableid+1;
begin
v_sql:='select count(1) from rmzh.'|| tname.coretablename;
execute immediate v_sql into v_tab_col_sum;
dbms_output.put_line(tableid||'---'||tname.coretablename||' --rmzh--- '||v_tab_col_sum);
exception
when not_exists then
if tname.coretablename in ('TB_INTF_RCGDXX','INTF_SYNC_TELANTHIS','INTF_ESBLOG','T_WORK_SHEET','CUT_WORKSHEET') then
dbms_output.put_line(tableid||'---'||tname.coretablename||' --not in both!!!!!!--- ');
else
v_sql:='select count(1) from infores.'||tname.coretablename;
execute immediate v_sql into v_tab_col_sum;
dbms_output.put_line(tableid||'---'||tname.coretablename||' --infores--- '||v_tab_col_sum);
end if;
end;
end loop;
end;
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/28713356/viewspace-1144067/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/28713356/viewspace-1144067/