oracle script: 重建索引
2013-11-14 08:14
295 查看
REM ============================================================= REM rebuild_index.sql REM 2013-11-14 REM Database Version : 7.3.X and above. REM SPOOLFILE easy_rebuild_index.sql REM REM Index is considered as candidate for rebuild when : REM - when deleted entries represent delete_percent (default 0.2) or more of the current entries REM - when the index depth is more then degree_level (default 5) levels.(height starts counting from 1) REM ============================================================= prompt accept Schema Char Prompt 'Schema name (% allowed) : '; accept delete_percent Number Default 0.2 Prompt 'Delete percent (0.2) : '; accept degree_level Number Default 5 Prompt 'Degree level (5) : '; accept ss_online Char Default 'Y' Prompt 'rebuild online(Y/N): '; accept is_logging Char default 'N' Prompt 'rebuild logging(Y/N): '; prompt spool easy_rebuild_index.sql; set serveroutput on; set verify off; Declare vc_rebuild varchar2(200); c_name INTEGER; ignore INTEGER; height index_stats.height%TYPE := 0; lf_rows index_stats.lf_rows%TYPE := 0; del_lf_rows index_stats.del_lf_rows%TYPE := 0; distinct_keys index_stats.distinct_keys%TYPE := 0; cursor c_indx is select owner, table_name, index_name from dba_indexes where owner like upper('&schema') And Owner Not In ('SYS', 'SYSTEM') And Table_Name Not Like 'BIN$%' and temporary = 'N'; begin dbms_output.enable(1000000); c_name := DBMS_SQL.OPEN_CURSOR; For R_Indx In C_Indx Loop Dbms_Sql.Parse(c_name, 'analyze index ' || r_indx.owner || '.' || r_indx.index_name || ' validate structure', DBMS_SQL.NATIVE); ignore := DBMS_SQL.EXECUTE(c_name); select HEIGHT, decode(LF_ROWS, 0, 1, LF_ROWS), DEL_LF_ROWS, decode(DISTINCT_KEYS, 0, 1, DISTINCT_KEYS) into height, lf_rows, del_lf_rows, distinct_keys From Index_Stats; If (Height > °ree_level) Or ((Del_Lf_Rows / Lf_Rows) > &delete_percent) Then select 'alter index'|| R_Indx.Owner||'.'||R_Indx.Index_Name||' rebuild ' ||Decode(Upper('&is_Online'),'Y',' online ','') ||Decode(Upper('&Is_Logging'),'N',' nologging ',' logging ') ||';' Into Vc_Rebuild From Dual; dbms_output.put_line(Vc_Rebuild); end if; end loop; DBMS_SQL.CLOSE_CURSOR(c_name); end; / spool off; Set Verify On;
相关文章推荐
- 基于 Red Hat 的发行版 Oracle Linux 正式发布Oracle Linux 7.1
- Oracle 10g R2不能使用EM的问题
- PreparedStatement中in子句的处理
- 基于 Red Hat 的发行版 Oracle Linux 正式发布Oracle Linux 7.1
- 数据库自动备份脚本
- ActionScript 3.0 编程体验
- 解决oracle用户连接失败的解决方法
- oracle的一些tips技巧
- Oracle 下的开发日积月累
- Oracle存储过程之数据库中获取数据实例
- Windows下ORACLE 10g完全卸载的方法分析
- Oracle 函数大全[字符串函数,数学函数,日期函数]第1/4页
- ORACLE LATERAL-SQL-INJECTION 个人见解
- Oracle Connect to Idle Instance解决方法
- oracle sys_connect_by_path 函数 结果集连接
- Oracle捕获问题SQL解决CPU过渡消耗
- oracle dba 应该熟悉的命令
- Oracle11.2 命令行手工最简创建数据库的过程
- Oracle 数据库自动存储管理-安装配置
- 基于oracle中锁的深入理解