ITPub博客

首页 > 数据库 > Oracle > Oracle 普通table 转换为partition table

Oracle 普通table 转换为partition table

原创 Oracle 作者:tolilong 时间:2015-12-03 11:01:11 0 删除 编辑

1.创建eg table
SQL> create table pp (id int,dt date);

Table created.

SQL> create index pp_index on pp(id);

index created.

begin
for i in 1..10000000 loop
if mod(i,3)=1 then
   insert into pp values(i,to_date('2013/6/6','yyyy/mm/dd'));
elsif mod(i,3)=2 then
   insert into pp values(i,to_date('2014/6/6','yyyy/mm/dd'));
else
   insert into pp values(i,to_date('2015/5/5','yyyy/mm/dd'));
end if;
end loop;
commit;
end;
/

现在将pp表转换为partition table.

2.create partition table
SQL> edit
Wrote file afiedt.buf

  1  create table pp_copy
  2  (id int,dt date)
  3  partition by range(dt)
  4  (partition p1 values less than(to_date('2014/01/01','yyyy/mm/dd')) tablespace users,
  5   partition p2 values less than(to_date('2015/01/01','yyyy/mm/dd')) tablespace users,
  6   partition p3 values less than(to_date('2016/01/01','yyyy/mm/dd')) tablespace users,
  7*  partition p4 values less than(maxvalue) tablespace users)
SQL> /


SQL> insert into pp_copy select * from pp;

10000000 rows created.

SQL> commit;

Commit complete.

SQL> drop table pp purge;

Table dropped.

SQL> alter table pp_copy rename to pp;

Table altered.

SQL> create index pp_index on pp(id) tablespace users local;

Index created.

如果有package,procedure,view则需要重新编译。
alter package package_name compile;
alter procedure procedure_name compile;
alter view view_name compile;

来自 “ ITPUB博客 ” ,链接:https://blog.itpub.net/24237320/viewspace-1852252/ ,如需转载,请注明出处,否则将追究法律责任。

请登录后发表评论 登录
全部评论

注册时间:2010-07-13

  • 博文量
    406
  • 访问量
    1208738