First of all you have to check if redefinition is allowed for your table.
If the following procedure returns an exception you are not allowed:
BEGIN
DBMS_REDEFINITION.CAN_REDEF_TABLE(
uname => '<USER NAME>',
orig_table => '<TABLE NAME>'
);
END;
/
If the table can be redefined you have to create an interim table on the same schema with the desired attributes. The execute (no column mapped in your table):
BEGIN
DBMS_REDEFINITION.start_redef_table (
uname => '<USER NAME>',
orig_table => '<TABLE NAME>',
int_table => 'INTERIM'
);
END;
/
If everything is ok you can finish the process executing the procedure:
BEGIN
DBMS_REDEFINITION.finish_redef_table (
uname => '<USER NAME>',
orig_table => '<TABLE NAME>',
int_table => 'INTERIM');
END;
/
Before finishing redefinition with the previous procedure you can create indexes, constraints, etc.. on the interim table.
If you want to keep the interim table synchronized with the original table you also might need:
BEGIN
DBMS_REDEFINITION.sync_interim_table (
uname => '<USER NAME>',
orig_table => '<TABLE NAME>',
int_table => 'INTERIM');
END;
/
to be called before the FINISH_REDEF_TABLE Procedure.
dbms_redefinition.copy_table_dependents(..); can be useful to complete the job.
To abort the redefinition procedure you might need:
BEGIN
DBMS_REDEFINITION.abort_redef_table (
uname => '<USER NAME>',
orig_table => '<TABLE NAME>',
int_table => 'INTERIM');
END;
/
Pay attention, you might need a lot of space if the original table is big.
If the system is on line redefinition should be monitored. It might be heavy.