I've got a cursor that returns indexes from user_indexes
with status = 'UNUSABLE'
and print them in the output tab:
DECLARE
cur sys_refcursor;
BEGIN
FOR iStat IN (SELECT INDEX_NAME FROM USER_INDEXES WHERE STATUS = 'UNUSABLE' ORDER BY INDEX_NAME) LOOP
DBMS_OUTPUT.PUT_LINE('ALTER INDEX '||iStat.INDEX_NAME||' REBUILD');
END LOOP;
END;
These are some of the list of indexes that return:
ALTER INDEX II_LKP_DRV_POLRIECUB_REA_MISC REBUILD;
ALTER INDEX IND1_CM_FACT_RVA_COMISION REBUILD;
ALTER INDEX IND2_CM_FACT_RVA_COMISION REBUILD;
ALTER INDEX INDX_SN_FACT_RECLA_ADJ_SINI REBUILD;
I did a stored procedure to do an alter table
on those indexes returned at the cursor (I only used 2 indexes for testing purposes):
CREATE OR REPLACE PROCEDURE status_index
AS
cur sys_refcursor;
BEGIN
FOR iStat IN (SELECT INDEX_NAME FROM USER_INDEXES WHERE INDEX_NAME IN ('II_LKP_DRV_POLRIECUB_REA_MISC', 'INDX_SN_FACT_RECLA_ADJ_SINI') AND STATUS = 'UNUSABLE' ORDER BY INDEX_NAME) LOOP
'ALTER INDEX ' || iStat.INDEX_NAME || ' REBUILD';
END LOOP;
END;
It works if I use the DBMS_OUTPUT.PUT_LINE
, but if I use theALTER INDEX
at the time I run the procedure, it throws the error below:
ORA-06550: line 2, column 5
PLS-00905: object ECCO_A.STATUS_INDEX is invalid
ORA-06550: line 2, column 5
PL/SQL: Statement ignored
I would appreciate if someone could help me fix this error.