普通表转为分区表(三)-exchange

来源:互联网 发布:mac 查看文件夹大小 编辑:程序博客网 时间:2024/05/12 08:36



创建分区表结构
create table ttvv
   (id  number,name varchar2(30))
   partition by range(id)
   (
   partition p1 values less than (40000),
   partition p2 values less than (100000)
   );
   
   
SQL> select table_name,partition_name from user_tab_partitions where table_name='TTVV';


TABLE_NAME                     PARTITION_NAME
------------------------------ ------------------------------
TTVV                           P1
TTVV                           P2


创建分区对应的基表(重新命名新的字段id name) (注意范围与分区表范围结构一致否则交换报错)
create table t1 as select object_id id,owner name from tt where object_id<40000; 
create table t2 as select object_id id,owner name from tt where object_id>=40000 and object_id<100000; 


基表与分区交换
alter table ttvv exchange partition p1 with table t1;
alter table ttvv exchange partition p2 with table t2;
0 0
原创粉丝点击