Anu*_*mar 1 oracle database-administration oracle11g
我是数据库的新手.我想在oracle中对现有的大型数据库表进行系统分区.有人可以建议我如何在oracle数据库中为现有表实现系统分区?
注意我只是在寻找不寻找范围或哈希或复合分区的系统分区.
据我所知,现有的表无法分区.你将不得不重新创建它.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
);
Run Code Online (Sandbox Code Playgroud)
如果要对该表进行分区,则第一步是重命名该表:
alter table t_table rename to old_table;
Run Code Online (Sandbox Code Playgroud)
然后,创建新表
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
);
Run Code Online (Sandbox Code Playgroud)
现在,您可以将旧表中的表行插入到新表中.您的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;
Run Code Online (Sandbox Code Playgroud)
现在你可以放弃旧桌子了.
drop table old_table;
Run Code Online (Sandbox Code Playgroud)