The following example demonstrates online redefinition with FILE_DATASTORE and resizing a text column
prompt> echo "Hello World" >/home/oracle/world.txt
prompt> echo "Hello Oracle" >/home/oracle/oracle.txt
prompt> echo "Hello John" >/home/oracle/john.txt
REM Grant privleges required for online redefinition.
GRANT execute ON DBMS_REDEFINITION TO tc;
grant create any table, alter any table, drop any table, lock any table, select any table, ctxapp to tc;
connect tc/tc
create table ptab (a number primary key, b varchar2(40)) partition by range(a)
(partition ptab1 values less than (10),
partition ptab2 values less than (20),
partition ptab3 values less than (30));
insert into ptab values (1,'/home0/oracle/world.txt');
insert into ptab values (12,'/home0/oracle/oracle.txt');
insert into ptab values (28,'/home0/oracle/john.txt');
commit;
select * from ptab
-- Create partitioned index
create index ptabx on ptab(b) indextype is ctxsys.context
local (partition ptabx1, partition ptabx2, partition ptabx3)
parameters ('datastore ctxsys.file_datastore filter ctxsys.null_filter');
select index_name, status, domidx_status, domidx_opstatus
from user_indexes where index_name = 'PTABX';
select * from ctx_user_index_errors;
select * from ptab where contains(b,'hello')>0;
BEGIN
DBMS_REDEFINITION.CAN_REDEF_TABLE(user,'PTAB',
DBMS_REDEFINITION.CONS_USE_PK);
END;
/
-- Creating Interim Table
CREATE TABLE tc.int_ptab
(id NUMBER(5) primary key,
text VARCHAR2(132)) partition by range(id)
(partition int_ptab1 values less than (10),
partition int_ptab2 values less than (20),
partition int_ptab3 values less than (30));
--create table ptab (a number primary key, b varchar2(40)) partition by range(a)
--(partition ptab1 values less than (10),
--partition ptab2 values less than (20),
--partition ptab3 values less than (30));
-- Start the redefinition process
BEGIN
DBMS_REDEFINITION.START_REDEF_TABLE('tc', 'ptab','int_ptab',
'a id, b text',
dbms_redefinition.cons_use_pk);
END;
/
select * from ptab where contains(b,'hello')>0;
select * from int_ptab;
-- Create partitioned index on interim table
create index int_ptabx on int_ptab(text) indextype is ctxsys.context
local (partition int_ptabx1, partition int_ptabx2, partition int_ptabx3)
parameters ('datastore ctxsys.file_datastore filter ctxsys.null_filter');
select index_name, status, domidx_status, domidx_opstatus
from user_indexes where index_name like '%PTABX';
select * from ctx_user_index_errors;
select * from ptab where contains(b,'hello')>0;
select * from int_ptab where contains(text,'hello')>0;
-- Optionally, synchronize the Interim Table
BEGIN
DBMS_REDEFINITION.SYNC_INTERIM_TABLE('tc', 'ptab', 'int_ptab');
END;
/
-- Complete the redefinition
BEGIN
DBMS_REDEFINITION.FINISH_REDEF_TABLE('tc', 'ptab', 'int_ptab');
END;
/
-- Be aware that the names of the columns, constraints, indexes, and
-- triggers do not have the names they had on the source table.
desc ptab
desc int_ptab
select * from ptab where contains(text,'hello')>0;
select * from int_ptab where contains(b,'hello')>0;
-- You can rename the columns
ALTER TABLE ptab RENAME COLUMN id TO a;
ALTER TABLE ptab RENAME COLUMN text TO b;
select * from ptab where contains(b,'hello')>0;
-- Drop the interim table.
drop table int_ptab;
select * from ptab where contains(b,'hello')>0;
See Also:
The following related documentation provides additional details on the redefinition process described earlier in this section:
* Oracle Database Administrator's Guide gives detailed procedures and examples of redefining tables online.
* Oracle Database PL/SQL Packages and Types Reference includes information on syntax and other details on usage of procedures in the DBMS_REDEFINITION package.