[转帖]将非分区表转换为分区表_MySQL, Oracle及数据库讨论区_Weblogic技术|Tuxedo技术|中间件技术|Oracle论坛|JAVA论坛|Linux/Unix技术|hadoop论坛_联动北方技术论坛  
网站首页 | 关于我们 | 服务中心 | 经验交流 | 公司荣誉 | 成功案例 | 合作伙伴 | 联系我们 |
联动北方-国内领先的云技术服务提供商
»  游客             当前位置:  论坛首页 »  自由讨论区 »  MySQL, Oracle及数据库讨论区 »
总帖数
1
每页帖数
101/1页1
返回列表
0
发起投票  发起投票 发新帖子
查看: 3505 | 回复: 0   主题: [转帖]将非分区表转换为分区表        下一篇 
大红薯
注册用户
等级:少校
经验:1440
发帖:159
精华:0
注册:2011-7-21
状态:离线
发送短消息息给大红薯 加好友    发送短消息息给大红薯 发消息
发表于: IP:您无权察看 2011-8-1 11:36:32 | [全部帖] [楼主帖] 楼主

两种方法,
1.        创建一个同样结构的分区表,然后exchange,接着进行split
2.        使用在线重定义

create table justin (
ID NUMBER(18),
create_time date
);


第一种方法
首先创建分区表

create table justin_part (
ID NUMBER(18),
create_time date
)
partition by range(create_time)(partition p1012 values less than (to_date('201101','yyyymm')));


进行exchange

alter table justin_part exchange partition test with table justin;


接下来对表justin_part进行split

alter table justin split partition test at(to_date('201006','yyyymm')) into (partition p1005, partition test);
alter table justin split partition test at(to_date('201007','yyyymm')) into (partition p1006, partition test);
alter table justin split partition test at(to_date('201008','yyyymm')) into (partition p1007, partition test);
alter table justin split partition test at(to_date('201009','yyyymm')) into (partition p1008, partition test);
alter table justin split partition test at(to_date('201010','yyyymm')) into (partition p1009, partition test);
alter table justin split partition test at(to_date('201011','yyyymm')) into (partition p1010, partition test);
alter table justin split partition test at(to_date('201012','yyyymm')) into (partition p1011, partition test);


然后drop 源表 并对新生成的表重命名

drop table justin purge;
alter table justin_part rename to justin;


至此执行成功

第二种方法

采用在线重定义
首先创建中间表

create table justin_part (
ID NUMBER(18),
create_time date
)
partition by range(create_time)(partition p1004 values less than (to_date('201006','yyyymm')));


增添分区

alter table justin_part add partition p1005 values less than (to_date('201006','yyyymm'));
alter table justin_part add partition p1006 values less than (to_date('201007','yyyymm'));
alter table justin_part add partition p1007 values less than (to_date('201008','yyyymm'));
alter table justin_part add partition p1008 values less than (to_date('201009','yyyymm'));
alter table justin_part add partition p1009 values less than (to_date('201010','yyyymm'));
alter table justin_part add partition p1010 values less than (to_date('201011','yyyymm'));
alter table justin_part add partition p1011 values less than (to_date('201012','yyyymm'));
alter table justin_part add partition p1012 values less than (to_date('201101','yyyymm'));


开始在线重定义

SQL> exec dbms_redefinition.can_redef_table(user,'justin');
PL/SQL procedure successfully completed
SQL> BEGIN
2  DBMS_REDEFINITION.START_REDEF_TABLE(
3  uname => 'pur',
4  orig_table => 'justin',
5  int_table => 'justin_part',
6  col_mapping => NULL,
7  options_flag => DBMS_REDEFINITION.CONS_USE_ROWID);
8  END;
9  /
PL/SQL procedure successfully completed
SQL>
SQL> BEGIN
2  DBMS_REDEFINITION.FINISH_REDEF_TABLE(
3  uname => 'pur',
4  orig_table => 'justin',
5  int_table => 'justin_part');
6  END;
7  /
PL/SQL procedure successfully completed


检查表justin 发现已经分区,而表justin_part的分区已经消失




赞(0)    操作        顶端 
总帖数
1
每页帖数
101/1页1
返回列表
发新帖子
请输入验证码: 点击刷新验证码
您需要登录后才可以回帖 登录 | 注册
技术讨论