在pl/sql developer中,右键点击一个存储过程,在菜单中点击recompile就可以编译这个存储过程。
现在我希望写一个批处理的程序,在需要的时候自动执行编译过程,请问如何做?

解决方案 »

  1.   

    SQL> create or replace procedure reCompile is
      2      cursor cur_invalid_objects is
      3          select object_name,object_type from user_objects where status = 'INVALID';
      4      rec_columns cur_invalid_objects%rowtype;
      5      err_status numeric;
      6  begin
      7      dbms_output.enable(10000);
      8      open cur_invalid_objects;
      9      loop
     10          fetch cur_invalid_objects into rec_columns;
     11          exit when cur_invalid_objects%notfound;
     12          dbms_output.put_line
     13            ('Recompiling ' || rec_columns.object_type || ' ' || rec_columns.object_name);
     14          dbms_ddl.alter_compile(rec_columns.object_type,null,rec_columns.object_name);
     15      end loop;
     16      close cur_invalid_objects;
     17      exception
     18      when others then
     19      begin
     20           err_status:=sqlcode;
     21           dbms_output.put_line('Recompilation failed :' || sqlerrm(err_status));
     22           if (cur_invalid_objects%isopen) then
     23               close cur_invalid_objects;
     24           end if;
     25           exception when others then
     26           null;
     27      end;
     28  end reCompile;
     29  /Procedure createdSQL>