摘自:http://blog.csdn.net/edcvf3/article/details/8721655
ORACLE数据库支持在线(不关库)修改表的各种物理属性和逻辑属性,包括责增加/更改/删除分区、更改表空间、增加列、删除列、将表改为IOT表等等。
个人觉得将未分区的表重定义为分区表是用的最多的,因为一些DB前期设计未考虑周全,很多大表到后期都需要分区。(对大表做在线重定义的时候,个人建议尽量少做基于原表的大的查询或大的DML操作)
现在来简单测试一下这个强大的功能:
我们来使用主键的方式进行重定义:
在线重定义支持按键和按ROWID方式重定义。其中按键可以是按主键或有唯一索引的键
--
注意:在线重定义表需要大量空闲空间。
在线重定义表的时候可以做DML操作。
从10gR2开始,Oracle支持单个分区表的在线重定义
一般使用包DBMS_REDEFINITION 或EM执行在线重定义。
附注, 在oracle 10g中, dbms_redefinition包增加了COPY_TABLE_DEPENDENTS, REGISTER_DEPENDENT_OBJECT, UNREGISTER_DEPENDENT_OBJECT三个存储过程, 分别用来复制, 注册, 注销表的依赖对象, 如索引, 约束, 触发器等. 并增加了DBA_REDEFINITION_ERRORS数据字典视图, 用来查看在线重定义过程中出现的错误.
OCP 题库考察此知识点:
Q9. Which statement describes the effect of table redefinition on the triggers attached to the table?
A. All triggers on the table are invalidated and are automatically revalidated(使重新生效) with the next DML execution on the table.
B. All triggers on the table are invalidated and must be manually recompiled before the next DML execution on the table.
C. All triggers on the table remain valid.
D. Only triggers that are affected by the changes to the structure of the table are invalidated and automatically revalidated with the next DML execution on the table.
Answer: A
The following restrictions apply to the online redefinition of tables:
If the table is to be redefined using primary key or pseudo-primary keys (unique keys or constraints with all component columns having not nullconstraints), then the post-redefinition table must have the same primary key or pseudo-primary key columns. If the table is to be redefined using rowids, then the table must not be an index-organized table.
After redefining a table that has a materialized view log, the subsequent refresh of any dependent materialized view must be a complete refresh.
Tables that are replicated in an n-way master configuration can be redefined, but horizontal subsetting (subset of rows in the table), vertical subsetting (subset of columns in the table), and column transformations are not allowed.
The overflow table of an index-organized table cannot be redefined online independently.
Tables with fine-grained access control (row-level security) cannot be redefined online.
Tables for which Flashback Data Archive is enabled cannot be redefined online. You cannot enable Flashback Data Archive for the interim table.
Tables with BFILE
columns cannot be redefined online.
Tables with LONG
columns can be redefined online, but those columns must be converted to CLOBS
. Also, LONG RAW
columns must be converted to BLOBS
. Tables with LOB
columns are acceptable.
On a system with sufficient resources for parallel execution, and in the case where the interim table is not partitioned, redefinition of a LONG
column to aLOB
column can be executed in parallel, provided that:
The segment used to store the LOB
column in the interim table belongs to a locally managed tablespace with Automatic Segment Space Management (ASSM) enabled.
There is a simple mapping from one LONG
column to one LOB
column, and the interim table has only one LOB
column.
In the case where the interim table is partitioned, the normal methods for parallel execution for partitioning apply.
Tables in the SYS
and SYSTEM
schema cannot be redefined online.
Temporary tables cannot be redefined.
A subset of rows in the table cannot be redefined.
Only simple deterministic expressions, sequences, and SYSDATE
can be used when mapping the columns in the interim table to those of the original table. For example, subqueries are not allowed.
If new columns are being added as part of the redefinition and there are no column mappings for these columns, then they must not be declared NOT
NULL
until the redefinition is complete.
There cannot be any referential constraints between the table being redefined and the interim table.
Table redefinition cannot be done NOLOGGING
.
For materialized view logs and queue tables, online redefinition is restricted to changes in physical properties. No horizontal or vertical subsetting is permitted, nor are any column transformations. The only valid value for the column mapping string is NULL
.
You cannot perform online redefinition on a table that is partitioned if the table includes one or more nested tables.
You can convert a VARRAY
to a nested table with the CAST
operator in the column mapping. However, you cannot convert a nested table to a VARRAY
.