1.创建分区表示例
- create table pt3( id number)
- partition by range(id)
- ( partition p1 values less than (5000),
- partition p2 values less than (maxvalue)
- );
- SQL> create table test ( id number primary key,time date);
- Table created.
- SQL> INSERT INTO TEST SELECT ROWNUM, CREATED FROM USER_OBJECTS;
- SQL>commit;
- SQL> create table pt4(id,time)
- partition by range(time)
- (partition p1 values less than (to_date('2006-1-1','yyyy-mm-dd')),
- partition p2 values less than (maxvalue)
- ) as select id,time from test;
- SQL> rename test to test_old;
- Table renamed.
- SQL> rename pt4 to test;
- SQL> select count(*) from test partition (p1);
- COUNT(*)
- ----------
- 0
- SQL> select count(*) from test partition (p2);
- SQL> create table t ( id number primary key,time date);
- Table created.
- SQL> INSERT INTO T SELECT ROWNUM, CREATED FROM USER_OBJECTS;
- SQL>commit;
- SQL> create table pt4(id number,time date) partition by range(time) (partition p1 values less than (to_date('2006-1-1','yyyy-mm-dd')),partition p2 values less than (maxvalue));
- SQL>alter table pt4 exchange partition with table t without validation;
- SQL> rename t to t_old;
- Table renamed.
- SQL> rename pt4 to t;
- SQL> select count(*) from t ;
- SQL> select count(*) from t partition (p1);
- COUNT(*)
- ----------
- 0
- SQL> select count(*) from test partition (p2);
- SQL> create table t ( id number primary key,time date);
- Table created.
- SQL> INSERT INTO T SELECT ROWNUM, CREATED FROM USER_OBJECTS;
- SQL>commit;
- SQL> create table pt5(id number,time date)
- partition by range(time)
- ( partition p1 values less than (to_date('2011-7-1','yyyy-mm-dd')),
- partition p2 values less than (maxvalue)
- );
- SQL>conn / as sysdba
- SQL> exec dbms_redefinition.can_redef_table('HR','TEST_OLD');
- SQL> EXEC DBMS_REDEFINITION.START_REDEF_TABLE('HR','TEST_OLD','PT5','ID ID,TIME TIME');
- SQL> INSERT INTO TEST_OLD VALUES(55,SYSDATE);
- SQL>commit;
- SQL> SELECT * FROM TEST_OLD;
- SQL> SELECT COUNT(*) FROM PT5;
- COUNT(*)
- ----------
- 44
- SQL> SELECT COUNT(*) FROM PT5;
- COUNT(*)
- ----------
- 45
- SQL> EXEC DBMS_REDEFINITION.FINISH_REDEF_TABLE('HR','TEST_OLD','PT5');
- SQL> SELECT COUNT(*) FROM PT5;
- COUNT(*)
- ----------
- 45
- SQL> SELECT COUNT(*) FROM PT5;
- COUNT(*)
- ----------
- 45