oracle 重新编译用户无效对象
admin
2023-05-15 01:42:10
0次
oracle sys用户无效对象


select owner,object_name
, replace(object_type,' ','') object_type
,to_char(created,'yyyy-mm-dd') as created
,to_char(last_ddl_time,'yyyy-mm-dd') as last_ddl_time,
status
from dba_objects where status='INVALID' and owner='SYS';

OWNER   OBJECT_NAME           OBJECT_TYPE    CREATED     LAST_DDL_TIME  STATUS
------  --------------------- -------------  ----------- -------------- ----------
SYS     ALL_TAB_STATISTICS    VIEW           2011-09-17  2012-05-16     INVALID
SYS     USER_TAB_STATISTICS   VIEW           2011-09-17  2012-05-16     INVALID
SYS     ALL_IND_STATISTICS    VIEW           2011-09-17  2012-05-16     INVALID
SYS     USER_IND_STATISTICS   VIEW           2011-09-17  2012-05-16     INVALID
SYS     VALIDATE_ORDIM        PROCEDURE      2011-09-17  2012-05-16     INVALID
SYS     DBMS_CUBE_ADVISE      PACKAGEBODY    2011-09-17  2012-05-16     INVALID
SYS     DBMS_CUBE             PACKAGEBODY    2011-09-17  2012-05-16     INVALID

方法1:手动重新rebuilt

SQL>alter view sys.ALL_TAB_STATISTICS  compile; 

SQL>alter view sys.USER_TAB_STATISTICS compile;
 
SQL>alter view ALL_IND_STATISTICS      compile;
 
SQL>alter view sys.USER_IND_STATISTICS compile;

SQL>alter procedure sys.VALIDATE_ORDIM   compile;

SQL>alter package DBMS_CUBE_ADVISE compile body;
  
SQL>alter package DBMS_CUBE  compile body;


方法2:
oracle用户下执行

$cd $ORACLE_HOME/rdbms/admin
$sqlplus  /  as sysdba
SQL>@utlprp.sql


编译完成后,再次查看

SQL> select owner,object_name
  2  , replace(object_type,' ','') object_type
  3  ,to_char(created,'yyyy-mm-dd') as created
  4  ,to_char(last_ddl_time,'yyyy-mm-dd') as last_ddl_time,
  5  status
  6  from dba_objects where status='INVALID' and owner='SYS';

no rows selected         
                                                                                                                                                                                                                                                                                                                     方法3:
以下是一个转帖的方法
                                                                                                                           
--创建自动编译失效过程事务记录表
declare
  tabcnt integer := 0;
begin
  select count(*) into tabcnt from dba_tables where table_name='RECOMPILE_LOG';
  if tabcnt = 0 then
    execute immediate 'create table recompile_log(rdate date,errmsg varchar2(200))';
  end if;
end;
/
 
--创建编译失效对象的存储过程
create or replace procedure recompile_invalid_objects  
as
  str_sql varchar2(200);  --中间用到的sql语句
  p_owner varchar2(20);   --所有者名称,即SCHEMA
  errm varchar2(200);     --中间错误信息
begin
  /*****************************************************/
  p_owner := 'owner';/***用户名*************************/
  /*****************************************************/ 
  insert into recompile_log(rdate, errmsg) values(sysdate,'time to recompile invalid objects'); 
   
  --编译失效存储过程
  for invalid_procedures in (select object_name from all_objects
    where status = 'INVALID' and object_type = 'PROCEDURE' and owner=upper(p_owner))
  loop
    str_sql := 'alter procedure ' ||invalid_procedures.object_name || ' compile';
    begin
      execute immediate str_sql;
    exception
      When Others Then
      begin
        errm := 'error by obj:'||invalid_procedures.object_name||' '||sqlerrm;
        insert into recompile_log(rdate, errmsg) values(sysdate,errm);
      end;
    end;
  end loop;
   
  --编译失效函数
  for invalid_functions in (select object_name from all_objects
    where status = 'INVALID' and object_type = 'FUNCTION' and owner=upper(p_owner))
  loop
    str_sql := 'alter function ' ||invalid_functions.object_name || ' compile';
    begin
      execute immediate str_sql;
    exception
      When Others Then
      begin
        errm := 'error by obj:'||invalid_functions.object_name||' '||sqlerrm;
        insert into recompile_log(rdate, errmsg) values(sysdate,errm);
      end;
    end;
  end loop;
 
  --编译失效包
  for invalid_packages in (select object_name from all_objects
    where status = 'INVALID' and object_type = 'PACKAGE' and owner=upper(p_owner))
  loop
    str_sql := 'alter package ' ||invalid_packages.object_name || ' compile';
    begin
      execute immediate str_sql;
    exception
      When Others Then
      begin
        errm := 'error by obj:'||invalid_packages.object_name||' '||sqlerrm;
        insert into recompile_log(rdate, errmsg) values(sysdate,errm);
      end;
    end;
  end loop;
   
  --编译失效类型
  for invalid_types in (select object_name from all_objects
    where status = 'INVALID' and object_type = 'TYPE' and owner=upper(p_owner))
  loop
    str_sql := 'alter type ' ||invalid_types.object_name || ' compile';
    begin
      execute immediate str_sql;
    exception
      When Others Then
      begin
        errm := 'error by obj:'||invalid_types.object_name||' '||sqlerrm;
        insert into recompile_log(rdate, errmsg) values(sysdate,errm);
      end;
    end;
  end loop;
 
  --编译失效索引
  for invalid_indexs in (select object_name from all_objects
    where status = 'INVALID' and object_type = 'INDEX' and owner=upper(p_owner))
  loop
    str_sql := 'alter index ' ||invalid_indexs.object_name || ' rebuild';
    begin
      execute immediate str_sql;
    exception
      When Others Then
      begin
        errm := 'error by obj:'||invalid_indexs.object_name||' '||sqlerrm;
        insert into recompile_log(rdate, errmsg) values(sysdate,errm);
      end;
    end;
  end loop;
 
  --编译失效触发器
  for invalid_triggers in (select object_name from all_objects
    where status = 'INVALID' and object_type = 'TRIGGER' and owner=upper(p_owner))
  loop
    str_sql := 'alter trigger ' ||invalid_triggers.object_name || ' compile';
    begin
      execute immediate str_sql;
    exception
      When Others Then
      begin
        errm := 'error by obj:'||invalid_triggers.object_name||' '||sqlerrm;
        insert into recompile_log(rdate, errmsg) values(sysdate,errm);
      end;
    end;
  end loop;
  
end;
/
 
--创建任务计划,每天早上8点整执行该任务,且保证此任务有且只有一个
declare 
  jobcnt integer :=0;
  job_recompile number := 0;
  str_sql varchar2(200);
begin 
  select count(*) into jobcnt from all_jobs where what = 'recompile_invalid_objects;' and broken = 'N';
  if jobcnt > 0 then
    for jobs in (select job from all_jobs where what = 'recompile_invalid_objects;' and broken = 'N')
    loop
      str_sql := 'begin dbms_job.remove('||jobs.job||'); end;';
      begin
        execute immediate str_sql;
      exception
        When Others Then null;
      end;
    end loop; 
  end if;
  --创建任务计划
  dbms_job.submit(job_recompile,'recompile_invalid_objects;',sysdate,'TRUNC(SYSDATE + 1) + 8/24');
  --启动任务计划
  dbms_job.run(job_recompile);
end;
/


相关内容

热门资讯

空调连续工作多久需要停机休息 空调连续工作的时间取决于多个因素,包括空调的型号、功率、使用环境和维护情况等。一般来说,空调可以连续...
空调哪个符号是除湿的 空调除湿功能通常用一个水滴形状的符号表示。不同品牌和型号的空调遥控器可能会有所差异,但一般来说,除湿...
格力空调多长时间加一次氟利昂 1、一般情况下,空调对氟利昂的使用量是非常小的,所以在空调使用了四年左右的时候再考虑加也没问题。2、...
空调用多长时间需要加氟一次 一般情况下是五年。当出现以下这几种情况时,空调才需要加氟。1、空调的室内机和室外机各有两个接口,当接...
格调生活·C标思享荟:卡萨帝在... 9月12日的郑州龙湖金融岛,夜风轻拂,灯光璀璨。“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑...
品牌价值破千亿、高端份额持续领... 9月12日,“C标时刻共传奇——卡萨帝思享荟暨20周年品牌盛典郑州站”在郑州龙湖金融岛举办。2026...
空调主板坏了修800还是换新的 空调主板坏了是修还是换新,需要考虑多个因素,以下是一些建议:1. 维修成本:如果维修费用较低,比如 ...
空调开多久需要休息多长时间 问题:空调开多久需要休息多长时间回答:1、在使用空调的过程中,一般空调开7~8个小时左右需要休息2~...
中央空调多长时间清洗一次 1、一般空调开机前清洗一次即可,空调开机中间时段再清洗一次,空调关机时清洗一次,这样比较合理。2、空...
中央空调氟利昂多久加一次 看空调制热和制冷程度,很多人的观点认为氟利昂必须一年放一次,其实这个观点是错误的,理解上面有点偏差,...