如何在 Oracle 11g 中创建系统分区?

How to make System partition in Oracle 11g?

我是数据库的新手。我想在 oracle 中为现有的大型数据库 table 做系统分区。有人可以建议 我如何为 oracle 数据库中现有的 table 实现系统分区?

注意我只是在寻找系统分区而不是在寻找范围或哈希或复合分区。

据我所知,现有的 table 无法分区。您将不得不重新创建它。 有一个名为 dbms_redefinition 的 Oracle 包仅适用于此场景(有关详细信息,请参阅 https://docs.oracle.com/database/121/ARPLS/d_redefi.htm),但我将提供一个不使用此包的非常简单的示例。

假设您有以下未分区的 table:

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

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

alter table t_table rename to old_table;

然后,创建新的 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
);     

现在您可以将旧 table 中的 table 行插入到新 table 中。您的 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;

现在您可以放下旧的 table。

drop table old_table;