我一直在寻找一种方法来找到所有需要重新建立的索引。但是在网上找不到一个语法。
有没有同样的语法可以找到?
是这样的 不可用. 请看下面的例子。
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>