创建使用program对无效索引进行重建
2017-01-06 17:07
295 查看
--创建使用program对无效索引进行重建
shell脚本
匿名pl/sql
创建procedure
shell脚本
匿名pl/sql
创建procedure
--模拟将索引不可用 SYS@PROD2> alter table scott.emp move; Table altered. SYS@PROD2> alter table scott.dept move; Table altered. SYS@PROD2> select 'alter index '||owner||'."'||index_name||'" rebuild;' from dba_indexes where OWNER='SCOTT' and status='UNUSABLE'; 'ALTERINDEX'||OWNER||'."'||INDEX_NAME||'"REBUILD;' ------------------------------------------------------------------------------------ alter index SCOTT."PK_DEPT" rebuild; alter index SCOTT."PK_EMP" rebuild;
1.通过shell脚本实现 [oracle@ocm1 ~]$ vi index_re.sh --编写脚本 [oracle@ocm1 ~]$ cat index_re.sh #!/bin/bash export ORACLE_BASE=/u01/app/oracle export ORACLE_HOME=/u01/app/oracle/product/11.2.0/dbhome_1 export PATH=$ORACLE_HOME/bin:$PATH export ORACLE_SID=PROD2 sqlplus / as sysdba <<EOF spool /tmp/i.sql rep select 'alter index '||owner||'."'||index_name||'" rebuild;' from dba_indexes where OWNER='SCOTT' and status='UNUSABLE'; spool off ho sed '/^alter index /p' -n /tmp/i.sql > /tmp/i1.sql start /tmp/i1.sql EOF [oracle@ocm1 ~]$ chmod +x index_re.sh --给予执行权限 [oracle@ocm1 ~]$ ./index_re.sh SQL*Plus: Release 11.2.0.3.0 Production on Fri Jan 6 15:58:20 2017 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options SYS@PROD2> SYS@PROD2> 'ALTERINDEX'||OWNER||'."'||INDEX_NAME||'"REBUILD;' ------------------------------------------------------------------------------------ alter index SCOTT."PK_DEPT" rebuild; alter index SCOTT."PK_EMP" rebuild; SYS@PROD2> SYS@PROD2> SYS@PROD2> Index altered. Index altered. SYS@PROD2> Disconnected from Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options [oracle@ocm1 ~]$ sqlplus / as sysdba SQL*Plus: Release 11.2.0.3.0 Production on Fri Jan 6 15:58:30 2017 Copyright (c) 1982, 2011, Oracle. All rights reserved. Connected to: Oracle Database 11g Enterprise Edition Release 11.2.0.3.0 - Production With the Partitioning, OLAP, Data Mining and Real Application Testing options --验证索引确实被重建 SYS@PROD2> select 'alter index '||owner||'."'||index_name||'" rebuild;' from dba_indexes where OWNER='SCOTT' and status='UNUSABLE'; no rows selected
2.编写匿名sql SYS@PROD2> alter table scott.dept move; al Table altered. SYS@PROD2> alter table scott.emp move; Table altered. SYS@PROD2> begin 2 for i in (select index_name from user_indexes where status='UNUSABLE') loop 3 execute immediate 'alter index "'||i.index_name||'" rebuild'; 4 end loop; 5 end; 6 / PL/SQL procedure successfully completed. SYS@PROD2> save index_plsql.sql Created file index_plsql.sql SYS@PROD2> conn scott/tiger Connected. SCOTT@PROD2> start index_plsql.sql PL/SQL procedure successfully completed. SCOTT@PROD2> select index_name,status from user_indexes; INDEX_NAME STATUS ------------------------------ -------- PK_EMP VALID PK_DEPT VALID
3.创建procedure SCOTT@PROD2> create or replace procedure index_rebuild 2 is 3 begin 4 for i in (select index_name from user_indexes where status='UNUSABLE') loop 5 execute immediate 'alter index "'||i.index_name||'" rebuild'; 6 end loop; 7 end; 8 / Procedure created. SCOTT@PROD2> save index_procudure.sql Created file index_procudure.sql SCOTT@PROD2> alter table emp move; Table altered. SCOTT@PROD2> alter table dept move; Table altered. SCOTT@PROD2> select index_name,status from user_indexes; INDEX_NAME STATUS ------------------------------ -------- PK_EMP UNUSABLE PK_DEPT UNUSABLE SCOTT@PROD2> exec index_rebuild; PL/SQL procedure successfully completed. SCOTT@PROD2> select index_name,status from user_indexes; INDEX_NAME STATUS ------------------------------ -------- PK_EMP VALID PK_DEPT VALID
相关文章推荐
- 使用Lucene对预处理后的文档进行创建索引(可执行)
- PLSQL_Oracle分区表和相应的分区索引管理和使用(案例)(创建交易表等大表时进行分区提高效率)
- 使用Lucene对预处理后的文档进行创建索引(可运行)
- 使用 For 循环的自动索引功能创建数组y1=sin(x/10)和y2=cos(x/10),(x=0-99),并分别用一个波形图和一个波形图表来进行显示。
- 使用VS2008进行VSTO-Addin实战开发-创建自己的工具栏(二)
- 各类索引的创建和使用方法
- 如何恢复一个非用户sa创建的数据库,且使用原用户创建者进行访问
- Oracle中重建索引时如何解决“无法为表空间 XXXXXX 中的段创建INITIAL区”错误
- 精通cobol--9.12.2 使用SET语句对索引进行算术运算
- C#创建数字证书并导出为pfx,并使用pfx进行非对称加解密
- 如何对动态创建控件进行验证以及在Ajax环境中的使用
- 创建索引视图时提示架构绑定无效,名称必须由两部分构成
- 如何对动态创建控件进行验证以及在Ajax环境中的使用
- 索引的创建及使用(sqlserver 2005)
- 回发或回调参数无效。在配置中使用 或在页面中使用 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。
- 因为使用了无效的方法(HTTP 动作)进行访问。
- Oracle 的 索 引 的 创 建 :索引的创建方法,使用场合及建议
- 使用Lucene进行全文检索(一)---处理索引
- 回发或回调参数无效。在配置中使用 或在页面中使用 启用了事件验证。出于安全目的,此功能验证回发或回调事件的参数是否来源于最初呈现这些事件的服务器控件。如果数据有效并且是预期的,则使用 ClientScriptManager.RegisterForEventValidation 方法来注册回发或回调数据以进行验证。
- Factory 定义一个接口,客户可以使用这个接口创建一个对象.同时,我们还可以控制对那个类进行实例化