My Error is for the execute immediate.
Even tho I pass a direct alter index stmt it doesn't work.
ANy reason ??


SQL> CREATE OR REPLACE PROCEDURE index_rebuilt (
2 table_name IN VARCHAR2)
3 IS
4 TYPE cv_type IS REF CURSOR;
5 cv cv_type;
6 val VARCHAR2(32767);
7 BEGIN
8 /* Construct the very dynamic query and open the cursor. */
9 OPEN cv FOR
10 'select index_name from dba_indexes where table_name = ''' || table_name || ''' and status = '
'UNUSABLE''';
11 LOOP
12 /* Fetch the next row, and stop if no more rows. */
13 FETCH cv INTO val;
14 EXIT WHEN cv%NOTFOUND;
15 EXECUTE IMMEDIATE 'ALTER INDEX MDM3.SYS_C007499 REBUILD ONLINE';
16 END LOOP;
17 CLOSE cv;
18 EXECUTE IMMEDIATE 'ALTER INDEX MDM3.SYS_C007499 REBUILD ONLINE';
19 END;
20 /

Procedure created.

SQL>
SQL>
SQL> exec index_rebuilt('test');
BEGIN index_rebuilt('test'); END;

*
ERROR at line 1:
ORA-01031: insufficient privileges
ORA-06512: at "MDM3.INDEX_REBUILT", line 18
ORA-06512: at line 1


SQL>