1.DETERMINE IF THE TABLE CAN BE REDEFINED ONLINE
BEGIN
DBMS_REDEFINITION.CAN_REDEF_TABLE('schema_name','original_TABLE', DBMS_REDEFINITION.CONS_USE_ROWID);
END;
/
2.CREATE THE INTERIM TABLE
CREATE TABLE "schema_name"."original_TABLE_INTERIM" AS SELECT * FROM "schema_name"."original_TABLE" WHERE 1=2;
3.PARALLELISM FOR LARGE TABLES
ALTER SESSION FORCE PARALLEL DML PARALLEL 8;
ALTER SESSION FORCE PARALLEL QUERY PARALLEL 8;
4.START THE REDEFINITION
BEGIN
DBMS_REDEFINITION.START_REDEF_TABLE(
uname => 'schema_name',
orig_table => 'original_TABLE',
int_table => 'original_TABLE_INTERIM',
options_flag => DBMS_REDEFINITION.CONS_USE_ROWID);
END;
/
5.COPY THE TABLE DEPENDENTS FROM THE ORIGINAL TABLE TO THE INTERIM TABLE
DECLARE
error_count pls_integer := 0;
BEGIN
DBMS_REDEFINITION.COPY_TABLE_DEPENDENTS('schema_name', 'original_TABLE', 'original_TABLE_INTERIM', dbms_redefinition.cons_orig_params, TRUE,TRUE,TRUE,FALSE, error_count);
DBMS_OUTPUT.PUT_LINE('errors := ' || TO_CHAR(error_count));
END;
/
6.check for invalid objects
select count(*),status from dba_objects where owner='schema_name' group by status;
select object_name from DBA_OBJECTS where owner='schema_name' and status='INVALID';
7.DO ONE FINAL SYNCHRONIZE BEFORE FINISHING THE REDEFINITION
BEGIN
DBMS_REDEFINITION.SYNC_INTERIM_TABLE('schema_name', 'original_TABLE', 'original_TABLE_INTERIM');
END;
/
8.FINISH THE REDEFINITION
exec DBMS_REDEFINITION.FINISH_REDEF_TABLE('schema_name', 'original_TABLE', 'original_TABLE_INTERIM');
9.Drop the interim table
drop TABLE "schema_name"."original_TABLE_INTERIM"