declare
cursor c_table is 
select table_name from objects_auto_reorg where nvl(date_reorg, sysdate-200) <= sysdate -200; 
l_ordre_rebuild varchar2(200);
l_table varchar2(50);
 
cursor c_index (l_table  varchar2) is
  select index_name from dba_indexes where table_name = l_table;
begin
  for l_cur in c_table loop
    begin
        l_table := l_cur.table_name;
        l_ordre_rebuild := 'ALTER TABLE SAPPAR.'||l_cur.table_name||' MOVE PARALLEL 6';  
        dbms_output.put_line (l_ordre_rebuild);
        execute immediate l_ordre_rebuild;
        for l_cur2 in c_index (l_table) loop
          begin
          l_ordre_rebuild := 'ALTER INDEX SAPPAR."'||l_cur2.index_name||'" REBUILD PARALLEL 6';
	    dbms_output.put_line (l_ordre_rebuild);
          execute immediate l_ordre_rebuild;
   	  exception when others then
          dbms_output.put_line ('Err rebuild '||l_ordre_rebuild||': '||sqlerrm);
        end;
        end loop;
    exception when others then 
	dbms_output.put_line ('Err rebuild '||l_ordre_rebuild||': '||sqlerrm);
    end;
    update objects_auto_reorg set date_reorg = sysdate where table_name = l_cur.table_name;
    commit;
    end loop;
exception
when others then
  dbms_output.put_line (l_ordre_rebuild||'err: '||sqlerrm);
end;
/

