FOR r IN (select 'DRR_DEV.' ||object_name as obj from dba_objects where object_type = 'INDEX'
and owner ='DRR_DEV')
LOOP
l_sql := 'ALTER INDEX '||r.obj||' REBUILD'||'';
execute immediate l_sql;
END LOOP;
Above FOR..IN loop, loop all the indexes of the particular schema and rebuild. I am getting few error at the beginning of the loop and the line of ALTER statement.
PL/SQL: SQL Statement ignored
PL/SQL: ORA-00942: table or view does not exist
PL/SQL: Statement ignored
PLS-00364: loop index variable 'R' use is invalid
I able to manually run the select statement but not through PLSQL block, what might go wrong?
It seems that you don't have a privilege to access DBA_OBJECTS. Either connect as SYS and run such a code, or grant required privileges to some other user, or - even better - connect as DDR_DEV.
I removed condition which restricts OWNER as there's no such column in USER_OBJECTS.
Here's an example ran on my SCOTT user: