Tag Archives: unusable state index(ORA-01502)

Oracle Script: How to Solve ‘unusable state index(ORA-01502)’

When a configuration tool is used, the following errors often occur ora-01502: index ‘xxx. Xxxxx’ or partition of such index is in an unusable state. The solution is to log in as DBA and run the following script

-- Please login with DBA privileges and execute
-- Repair all the indexes in UNUSABLE state, rebuild them
declare
  -- cursor to all UNUSABLE state indexes
  cursor c is 
    select index_name, owner 
    from dba_indexes 
    where status='UNUSABLE';
  
  owner dba_indexes.owner%type;
  index_name dba_indexes.index_name%type;
begin
  open c;
  loop 
       fetch c into index_name, owner; 
       exit when c%notfound;
       
       execute immediate 'alter index ' || owner || '.' || index_name || ' rebuild';
  end loop;
  close c;
end;

Thinking 1: why does normal operation cause an index to be unusable

Thinking 2: how to solve this problem without logging into DBA( I tried it from user_ In the indexes table, you can get all the indexes of the current user, but you can’t edit them.)