溫馨提示×

您好,登錄后才能下訂單哦!

密碼登錄×
登錄注冊(cè)×
其他方式登錄
點(diǎn)擊 登錄注冊(cè) 即表示同意《億速云用戶服務(wù)條款》

oracle 重新編譯用戶無效對(duì)象

發(fā)布時(shí)間:2020-08-16 08:56:32 來源:網(wǎng)絡(luò) 閱讀:1047 作者:Evils798 欄目:關(guān)系型數(shù)據(jù)庫
oracle sys用戶無效對(duì)象


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:手動(dòng)重新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用戶下執(zhí)行

$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:
以下是一個(gè)轉(zhuǎn)帖的方法
                                                                                                                           
--創(chuàng)建自動(dòng)編譯失效過程事務(wù)記錄表
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;
/
 
--創(chuàng)建編譯失效對(duì)象的存儲(chǔ)過程
create or replace procedure recompile_invalid_objects  
as
  str_sql varchar2(200);  --中間用到的sql語句
  p_owner varchar2(20);   --所有者名稱,即SCHEMA
  errm varchar2(200);     --中間錯(cuò)誤信息
begin
  /*****************************************************/
  p_owner := 'owner';/***用戶名*************************/
  /*****************************************************/ 
  insert into recompile_log(rdate, errmsg) values(sysdate,'time to recompile invalid objects'); 
   
  --編譯失效存儲(chǔ)過程
  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;
   
  --編譯失效函數(shù)
  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;
 
  --編譯失效觸發(fā)器
  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;
/
 
--創(chuàng)建任務(wù)計(jì)劃,每天早上8點(diǎn)整執(zhí)行該任務(wù),且保證此任務(wù)有且只有一個(gè)
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;
  --創(chuàng)建任務(wù)計(jì)劃
  dbms_job.submit(job_recompile,'recompile_invalid_objects;',sysdate,'TRUNC(SYSDATE + 1) + 8/24');
  --啟動(dòng)任務(wù)計(jì)劃
  dbms_job.run(job_recompile);
end;
/


向AI問一下細(xì)節(jié)

免責(zé)聲明:本站發(fā)布的內(nèi)容(圖片、視頻和文字)以原創(chuàng)、轉(zhuǎn)載和分享為主,文章觀點(diǎn)不代表本網(wǎng)站立場(chǎng),如果涉及侵權(quán)請(qǐng)聯(lián)系站長(zhǎng)郵箱:is@yisu.com進(jìn)行舉報(bào),并提供相關(guān)證據(jù),一經(jīng)查實(shí),將立刻刪除涉嫌侵權(quán)內(nèi)容。

AI