Oracle将统计信息导入数据字典存储过程

创建统计信息导入数据字典存储过程,执行以下脚本:
create or replace procedure p_func_impstats_new
(
   str_in_stattab in varchar2,
   str_in_statid in varchar2 default ''
)
as
    str_l_username     varchar2(200);
    tbl_l_tablename    array_varchar2;
    str_l_fullsql      varchar2(2000);
    str_l_error        varchar2(2000);
    str_l_stattab      varchar2(200) := str_in_stattab;
   
begin
    begin
        select username
          into str_l_username
          from user_users;
   
    exception
        when no_data_found then
            rollback;
            return;
    end;
   str_l_fullsql := '';
   str_l_fullsql := 'select  distinct c1 from ' || str_in_stattab||' where type=''T''';
   execute immediate  str_l_fullsql bulk collect into tbl_l_tablename;
    for i in 1 .. tbl_l_tablename.count loop
       str_l_fullsql := '';
       str_l_fullsql := 'begin dbms_stats.import_table_stats(ownname => '||''''||str_l_username||''''||
       ',tabname => '||''''||tbl_l_tablename(i)||''''||',stattab => '||''''||str_l_stattab||''''
       ||',statid => '||''''||str_in_statid||''''
        ||'); end;';
        begin
             execute immediate str_l_fullsql;
        exception
            when others then

                str_l_error := sqlerrm;
                insert into impstatslog (
                            err_msg,
                            err_time)
                    values (str_l_error,
                            sysdate);
                commit;
        end;
    end loop;
    commit;
exception
    when others then
                str_l_error := sqlerrm;
                insert into impstatslog (
                            err_msg,
                            err_time)
                    values (str_l_error,
                            sysdate);
                commit;
        return;
end p_func_impstats_new;
/

你可能感兴趣的:(oracle)