oracle - 查找所有需要重建的索引
问题描述
我一直在寻找一种方法来找到所有需要重建的索引。但是在网上找不到语法。
有没有找到相同的语法?
解决方案
它无法使用。看看下面的例子:
SQL> create table test (id number);
Table created.
SQL> create index i1t on test (id);
Index created.
使索引不可用:
SQL> alter index i1t unusable;
Index altered.
SQL> select index_name from user_indexes where status = 'UNUSABLE';
INDEX_NAME
------------------------------
I1T
重建它并再次检查其状态:
SQL> alter index i1t rebuild;
Index altered.
SQL> select index_name from user_indexes where status = 'UNUSABLE';
no rows selected
SQL>
当然,您不会手动重建它们 - 编写一个脚本来为您完成。例如:
SQL> set serveroutput on;
SQL> begin
2 for cur_r in (select index_name from user_indexes
3 where status = 'UNUSABLE'
4 )
5 loop
6 dbms_output.put_line('Rebuilding index ' || cur_r.index_name);
7 execute immediate 'alter index ' || cur_r.index_name || ' rebuild';
8 end loop;
9 end;
10 /
Rebuilding index I2T
Rebuilding index I1T
PL/SQL procedure successfully completed.
SQL>
推荐阅读
- azure-aks - 使用 azure AKS 的自定义指标
- javascript - 带外壳的子进程
- django - 如何在 Django 中设置本地文件和生产文件
- google-api-php-client - 带有 Admin SDK 的 Google API PHP 客户端 - listUsers 返回“无效输入”
- oracle - 分区表上的基于函数的索引
- php - 我使用 php exec 另一个 php 但这不起作用
- c# - Linq在datagridviewrow中按两个以上的2值分组
- django - 在 Django 表单类中访问用户数据
- java - Log4j2:仅记录到文件,没有控制台?
- ibm-cloud - 拒绝访问您的 IBM Cloud 帐户