create table niegc_part
(
part_id integer primary key,
part_date date,
part_dec varchar2(100)
)
partition by range(part_date) subpartition by hash(part_id)
subpartitions 2 store in(dw1,dw2)
(
partition part_01 values less than(to_date('2010-01-01','yyyy-mm-dd')) tablespace dw1,
partition part_02 values less than(to_date('2011-01-01','yyyy-mm-dd')) tablespace dw2,
partition part_03 values less than(maxvalue) tablespace dw1
);
先根据part_date进行范围分区,然后根据交易的ID将记录散列地存储在二个表空间中。
四、索引分区:
注意: 对某个字段已做了分区了,是不允许再建立索引分区的。这一点要非常注意。
全局索引建立时global子句允许指定索引的范围值,这个范围值为索引字段的范围值:
create index idx_part_id on niegc_part(part_dec)
global partition by range(part_dec)
(
partition idx_1 values less than('1000') tablespace dw,
partition idx_2 values less than(maxvalue) tablespace dw
)
局部索引分区的建立:(注意:表必须存在分区,此分区的个数必须和分区表的分区个数一样,不然是建立不起来的)
create index idx_part_id on niegc_part(part_dec)
local
(
partition idx_1 tablespace dw1,
partition idx_2 tablespace dw2
)
五、分区维护:(只对范围分区)
(1)、增加一个分区:分区范围只能往上增,不能增加一个少于原有的分区:
alter table niegc_part add partition part_03 values less than(maxvalue)
(2)、合并分区:(合并后的分区必须指下最后一个大value的分区)
alter table niegc_part merge partitions part_02,part_03 into partition part_03
(3)、删除一个分区:
alter table niegc_part drop partition part_01