如何在Oracle 11g中进行系统分区?

时间:2017-08-01 12:36:22

标签: oracle oracle11g database-administration

我对数据库很新。我想在oracle中对现有的大型数据库表进行系统分区。有人可以建议 如何在oracle数据库中实现现有表的系统分区?

注意我只是在寻找不寻找范围或散列或复合分区的系统分区。

1 个答案:

答案 0 :(得分:6)

据我所知,现有的表无法分区。你将不得不重新创建它。 对于这种情况,有一个名为dbms_redefinition的Oracle程序包(有关详细信息,请参阅https://docs.oracle.com/database/121/ARPLS/d_redefi.htm),但我将提供一个非常简单的示例,而不使用此程序包。

想象一下,您有以下非分区表:

create table T_TABLE
(
  pkey         NUMBER not null,
  t_data       VARCHAR2(250) not null,
  partitionkey NUMBER not null
);

如果要对该表进行分区,第一步是重命名该表:

alter table t_table rename to old_table;

然后,创建新表

create table T_TABLE
(
  pkey         NUMBER not null,
  t_data       VARCHAR2(250) not null,
  partitionkey NUMBER not null
)
partition by system
(
   partition p1 tablespace users,
   partition p2 tablespace users,
   partition p3 tablespace users
);     

现在,您可以将旧表中的表行插入到新表中。您的application / sql需要告诉服务器要插入哪个分区。 例如,像这样:

insert into t_table partition (p1) select * from old_table where partitionkey = 1;    
insert into t_table partition (p2) select * from old_table where partitionkey = 2;
insert into t_table partition (p3) select * from old_table where partitionkey = 3;        
commit;

现在你可以丢弃旧桌了。

drop table old_table;