---------------------------------------------------------------------
-- Connect as SYSDBA to grant privs to
---------------------------------------------------------------------
connect / as sysdba
grant execute on dbms_redefinition to
grant dba to
---------------------------------------------------------------------
-- Create new empty interim table...
---------------------------------------------------------------------
connect
CREATE TABLE NEW_TABLE AS SELECT * FROM
---------------------------------------------------------------------
-- Test if table can be redefined...
---------------------------------------------------------------------
EXEC DBMS_REDEFINITION.CAN_REDEF_TABLE('
---------------------------------------------------------------------
-- Start table redefinition...
---------------------------------------------------------------------
EXEC DBMS_REDEFINITION.START_REDEF_TABLE('
--------------------------------------------------------------------
-- Add ALL constraints, indexes, triggers, grants, etc...
---------------------------------------------------------------------
ALTER TABLE emp ADD PRIMARY KEY (empno);
---------------------------------------------------------------------
-- Finish the redefinition process (this will swap the two tables)...
---------------------------------------------------------------------
EXEC DBMS_REDEFINITION.FINISH_REDEF_TABLE('
---------------------------------------------------------------------
-- Drop the interim working table...
---------------------------------------------------------------------
DROP TABLE NEW_TABLE;