A blog by a system administrator and programmer.

Oracle moving index to another table space 
Tuesday, April 8, 2008, 05:04 PM - Programming
Posted by Freddy Chu
These days I am super busy. Nearly no time to write my blog. :(

There is so many people asking me how to move the index after created. As you know if you use plsql developer's GUI it will drop the constraint and add again with index. I don't know why it work like that but there is some simple solution.

ALTER INDEX <INDEX_NAME> REBUILD TABLESPACE <TALESPACE_NAME>

Here also show you a simple procedure to move all index of a table from one tablespace to another tablespace.


create or replace procedure MOVE_INDEX_BETWEEN_TABLESPACE(from_ts in string,
to_ts in string,
tablename in string) is
cursor index_names is
select user_indexes.index_name
from user_indexes
where user_indexes.table_name like upper(tablename)
and user_indexes.tablespace_name = upper(from_ts);
index_name user_indexes.index_name%type;
begin
open index_names;
loop
fetch index_names
into index_name;
exit when index_names%notfound;
if index_name is not null and to_ts is not null then
EXECUTE IMMEDIATE 'ALTER INDEX ' || index_name ||
' REBUILD TABLE_SPACE ' || to_ts;
end if;
end loop;
end MOVE_INDEX_BETWEEN_TABLESPACE;

add comment ( 119 views )   |  permalink   |   ( 3 / 4329 )

<<First <Back | 1 | 2 | Next> Last>>