今天给新同事讲数据维护过程的时候,他提出了写一个存储过程来检查日志表出错之后调用相关的存储过程,我们的日志表当中写入的表名和相应存储过程名称的差别是多了一个etl_,因此ETL_||table就是存储过程的名称.但是在编译过程当中无法将变量的存储过程名称在嵌套时执行,经过多方查找,一度怀疑是否可以执行这种变量式的存储过程,但是终于找到了方法,存储过程如下:
create or replace procedure yx_etl_proc as
cursor tb is select 'ETL_'||table_name
from etl_log
where end_time is null and (table_name,start_time) in (select table_name,max(start_time)
from etl_log where start_time>trunc(sysdate)
group by table_name);
c_proc_name etl_log.table_name%type;
begin
open tb;
loop
fetch tb into c_proc_name;
exit when tb%notfound;
execute immediate 'begin '||c_proc_name||';end;';
commit;
end loop;
close tb;
end yx_etl_proc;
粗体部分就是嵌套存储过程的执行方法。
来自 “ ITPUB博客 ” ,链接:http://blog.itpub.net/12216142/viewspace-509517/,如需转载,请注明出处,否则将追究法律责任。
转载于:http://blog.itpub.net/12216142/viewspace-509517/