oracle 重新编译用户无效对象

  1. oracle sys用户无效对象
  2. select owner,object_name
  3. , replace(object_type,' ','') object_type
  4. ,to_char(created,'yyyy-mm-dd') as created
  5. ,to_char(last_ddl_time,'yyyy-mm-dd') as last_ddl_time,
  6. status
  7. from dba_objects where status='INVALID' and owner='SYS';
  8. OWNER OBJECT_NAME OBJECT_TYPE CREATED LAST_DDL_TIME STATUS
  9. ------ --------------------- ------------- ----------- -------------- ----------
  10. SYS ALL_TAB_STATISTICS VIEW 2011-09-17 2012-05-16 INVALID
  11. SYS USER_TAB_STATISTICS VIEW 2011-09-17 2012-05-16 INVALID
  12. SYS ALL_IND_STATISTICS VIEW 2011-09-17 2012-05-16 INVALID
  13. SYS USER_IND_STATISTICS VIEW 2011-09-17 2012-05-16 INVALID
  14. SYS VALIDATE_ORDIM PROCEDURE 2011-09-17 2012-05-16 INVALID
  15. SYS DBMS_CUBE_ADVISE PACKAGEBODY 2011-09-17 2012-05-16 INVALID
  16. SYS DBMS_CUBE PACKAGEBODY 2011-09-17 2012-05-16 INVALID
  17. 方法1:手动重新rebuilt
  18. SQL>alter view sys.ALL_TAB_STATISTICS compile;
  19. SQL>alter view sys.USER_TAB_STATISTICS compile;
  20. SQL>alter view ALL_IND_STATISTICS compile;
  21. SQL>alter view sys.USER_IND_STATISTICS compile;
  22. SQL>alter procedure sys.VALIDATE_ORDIM compile;
  23. SQL>alter package DBMS_CUBE_ADVISE compile body;
  24. SQL>alter package DBMS_CUBE compile body;
  25. 方法2:
  26. oracle用户下执行
  27. $cd $ORACLE_HOME/rdbms/admin
  28. $sqlplus / as sysdba
  29. SQL>@utlprp.sql
  30. 编译完成后,再次查看
  31. SQL> select owner,object_name
  32. 2 , replace(object_type,' ','') object_type
  33. 3 ,to_char(created,'yyyy-mm-dd') as created
  34. 4 ,to_char(last_ddl_time,'yyyy-mm-dd') as last_ddl_time,
  35. 5 status
  36. 6 from dba_objects where status='INVALID' and owner='SYS';
  37. no rows selected
  38. 方法3:
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:
[javascript] view plain copy print ?
  1. 以下是一个转帖的方法
以下是一个转帖的方法
[javascript] view plain copy print ?
  1. --创建自动编译失效过程事务记录表
  2. declare
  3. tabcnt integer := 0;
  4. begin
  5. select count(*) into tabcnt from dba_tables where table_name='RECOMPILE_LOG';
  6. if tabcnt = 0 then
  7. execute immediate 'create table recompile_log(rdate date,errmsg varchar2(200))';
  8. end if;
  9. end;
  10. /
  11. --创建编译失效对象的存储过程
  12. create or replace procedure recompile_invalid_objects
  13. as
  14. str_sql varchar2(200); --中间用到的sql语句
  15. p_owner varchar2(20); --所有者名称,即SCHEMA
  16. errm varchar2(200); --中间错误信息
  17. begin
  18. /*****************************************************/
  19. p_owner := 'owner';/***用户名*************************/
  20. /*****************************************************/
  21. insert into recompile_log(rdate, errmsg) values(sysdate,'time to recompile invalid objects');
  22. --编译失效存储过程
  23. for invalid_procedures in (select object_name from all_objects
  24. where status = 'INVALID' and object_type = 'PROCEDURE' and owner=upper(p_owner))
  25. loop
  26. str_sql := 'alter procedure ' ||invalid_procedures.object_name || ' compile';
  27. begin
  28. execute immediate str_sql;
  29. exception
  30. When Others Then
  31. begin
  32. errm := 'error by obj:'||invalid_procedures.object_name||' '||sqlerrm;
  33. insert into recompile_log(rdate, errmsg) values(sysdate,errm);
  34. end;
  35. end;
  36. end loop;
  37. --编译失效函数
  38. for invalid_functions in (select object_name from all_objects
  39. where status = 'INVALID' and object_type = 'FUNCTION' and owner=upper(p_owner))
  40. loop
  41. str_sql := 'alter function ' ||invalid_functions.object_name || ' compile';
  42. begin
  43. execute immediate str_sql;
  44. exception
  45. When Others Then
  46. begin
  47. errm := 'error by obj:'||invalid_functions.object_name||' '||sqlerrm;
  48. insert into recompile_log(rdate, errmsg) values(sysdate,errm);
  49. end;
  50. end;
  51. end loop;
  52. --编译失效包
  53. for invalid_packages in (select object_name from all_objects
  54. where status = 'INVALID' and object_type = 'PACKAGE' and owner=upper(p_owner))
  55. loop
  56. str_sql := 'alter package ' ||invalid_packages.object_name || ' compile';
  57. begin
  58. execute immediate str_sql;
  59. exception
  60. When Others Then
  61. begin
  62. errm := 'error by obj:'||invalid_packages.object_name||' '||sqlerrm;
  63. insert into recompile_log(rdate, errmsg) values(sysdate,errm);
  64. end;
  65. end;
  66. end loop;
  67. --编译失效类型
  68. for invalid_types in (select object_name from all_objects
  69. where status = 'INVALID' and object_type = 'TYPE' and owner=upper(p_owner))
  70. loop
  71. str_sql := 'alter type ' ||invalid_types.object_name || ' compile';
  72. begin
  73. execute immediate str_sql;
  74. exception
  75. When Others Then
  76. begin
  77. errm := 'error by obj:'||invalid_types.object_name||' '||sqlerrm;
  78. insert into recompile_log(rdate, errmsg) values(sysdate,errm);
  79. end;
  80. end;
  81. end loop;
  82. --编译失效索引
  83. for invalid_indexs in (select object_name from all_objects
  84. where status = 'INVALID' and object_type = 'INDEX' and owner=upper(p_owner))
  85. loop
  86. str_sql := 'alter index ' ||invalid_indexs.object_name || ' rebuild';
  87. begin
  88. execute immediate str_sql;
  89. exception
  90. When Others Then
  91. begin
  92. errm := 'error by obj:'||invalid_indexs.object_name||' '||sqlerrm;
  93. insert into recompile_log(rdate, errmsg) values(sysdate,errm);
  94. end;
  95. end;
  96. end loop;
  97. --编译失效触发器
  98. for invalid_triggers in (select object_name from all_objects
  99. where status = 'INVALID' and object_type = 'TRIGGER' and owner=upper(p_owner))
  100. loop
  101. str_sql := 'alter trigger ' ||invalid_triggers.object_name || ' compile';
  102. begin
  103. execute immediate str_sql;
  104. exception
  105. When Others Then
  106. begin
  107. errm := 'error by obj:'||invalid_triggers.object_name||' '||sqlerrm;
  108. insert into recompile_log(rdate, errmsg) values(sysdate,errm);
  109. end;
  110. end;
  111. end loop;
  112. end;
  113. /
  114. --创建任务计划,每天早上8点整执行该任务,且保证此任务有且只有一个
  115. declare
  116. jobcnt integer :=0;
  117. job_recompile number := 0;
  118. str_sql varchar2(200);
  119. begin
  120. select count(*) into jobcnt from all_jobs where what = 'recompile_invalid_objects;' and broken = 'N';
  121. if jobcnt > 0 then
  122. for jobs in (select job from all_jobs where what = 'recompile_invalid_objects;' and broken = 'N')
  123. loop
  124. str_sql := 'begin dbms_job.remove('||jobs.job||'); end;';
  125. begin
  126. execute immediate str_sql;
  127. exception
  128. When Others Then null;
  129. end;
  130. end loop;
  131. end if;
  132. --创建任务计划
  133. dbms_job.submit(job_recompile,'recompile_invalid_objects;',sysdate,'TRUNC(SYSDATE + 1) + 8/24');
  134. --启动任务计划
  135. dbms_job.run(job_recompile);
  136. end;
  • 0
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值