在线重定义表可以将一个普通表转换成一个分区表。
exchange partition可以将一个分区表的一个分区和另一张表的数据互换,
也可以从普通表表迁移至分区表.
它通过更新数据字典来实现分区表与普通表的转换,所以速度非常快
SQL> create table LGX_PARTAB(
2 A INT,
3 B DATE)
4 PARTITION BY RANGE(A)(
5 PARTITION PART01 VALUES LESS THAN(10),
6 PARTITION PART02 VALUES LESS THAN(20),
7 PARTITION PART03 VALUES LESS THAN(MAXVALUE));
Table created.
SQL> INSERT INTO LGX_PARTAB VALUES(1,SYSDATE);
1 row created.
SQL> INSERT INTO LGX_PARTAB VALUES(11,SYSDATE);
1 row created.
SQL> COMMIT
2 ;
Commit complete.
SQL> SELECT * FROM LGX_PARTAB PARTITION (PART02);
A B
---------- ---------
11 19-JUN-09
SQL> CREATE TABLE LGX_TAB01(
2 A INT,
3 B DATE);
Table created.
SQL> ALTER TABLE LGX_PARTAB EXCHANGE PARTITION PART02
2 WITH TABLE LGX_TAB01;
Table altered.
SQL> SELECT * FROM LGX_TAB01;
A B
---------- ---------
11 19-JUN-09
SQL> SELECT * FROM LGX_PARTAB PARTITION (PART02);
no rows selected
记录已经成功交换到普通表中.
++++++++++++++++++++++++++++++++++++++++++++++++++++++++
SQL> INSERT INTO LGX_TAB01 VALUES(12,SYSDATE);
1 row created.
SQL> COMMIT;
Commit complete.
SQL> SELECT * FROM LGX_TAB01;
A B
---------- ---------
11 19-JUN-09
12 19-JUN-09
SQL> ALTER TABLE LGX_PARTAB EXCHANGE PARTITION PART02
2 WITH TABLE LGX_TAB01;
Table altered.
SQL> SELECT * FROM LGX_TAB01;
no rows selected
SQL> SELECT * FROM LGX_PARTAB PARTITION (PART02);
A B
---------- ---------
11 19-JUN-09
12 19-JUN-09
在次执行EXCHANGE PARTITION,数据从普通表交换到分区表中了.
++++++++++++++++++++++++++++++++++++++++++++++
注意:
$涉及交换的两表之间表结构必须一致,除非附加with validation子句;
$如果是从非分区表向分区表做交换,非分区表中的数据必须符合分区表中指定分区的规则,除非附加without validation子句;
$如果从分区表向分区表做交换,被交换的分区的数据必须符合分区规则,除非附加without validation子句;
$Global索引或涉及到数据改动了的global索引分区会被置为unusable,除非附加update indexes子句。
阅读(1717) | 评论(0) | 转发(0) |