Oracle 批量编译对象
Oracle 在导入数据时,往往会造成存储过程、触发器、视图、函数等对象失效,如果数量比较多,单个编译起来比较麻烦,这里介绍一种批量编译的方法:
- 
查询对象 
 select * from all_objects
  
- 
通过上面的查询结果,可以看到当前数据库的对象类型(索引、存储过程、表、视图、函数等)和状态( valid有效invalid无效),这个表是关键。
- 
下面就可以通过定义游标来遍历该表中的无效对象进行重新编译 
declare 
   objowner varchar2(50):='user01';
begin
   for obj in (select * from all_objects where status='invalid' and 
     object_type in('PROCEDURE','FUNCTION','VIEW','TRIGGER') 
     and owner=upper(objowner))
   loop
    begin
     execute immediate 'alter '||obj.object_type||' '||obj.object_name||' compile';
     exception
       when others then 
         dbms_output.put_line(sqlerrm);
     end;
   end loop;
end;
 
                     
                    
                 
                    
                
 
                
            
         
         浙公网安备 33010602011771号
浙公网安备 33010602011771号