ORA-01502: index 'xxx. xxxx' or partition of such index is in unusable state. Solution: Log On With DBA and run the following script.
- -- Log On with the DBA permission and execute
- -- Fix all indexes in the UNUSABLE status and rebuild them.
- Declare
- -- Cursor pointing to the index of all UNUSABLE states
- CursorCIs
- SelectIndex_name, owner
- FromDba_indexes
- WhereStatus ='Unusable';
- Owner dba_indexes.owner % type;
- Index_name dba_indexes.index_name % type;
- Begin
- OpenC;
- Loop
- FetchCIntoIndex_name, owner;
- ExitWhenC % notfound;
- ExecuteImmediate'Alter Index'| Owner |'.'| Index_name |'Rebuilt';
- EndLoop;
- CloseC;
- End;
Thought 1: Why does a normal operation cause an index to be unusable?
Thinking 2: how to solve this problem without logging on to the DBA? (I tried to get all the indexes of the current user from the user_indexes table, but they cannot be edited)