oracle中的分区表
oracle在处理大型的数据的时候为了更加高效的对数据进行存储,和查询,提供了针对大型数据操作的分区表,分区表一般用于数据量在上百G,和TB级别的数据,这样更好的支持了对大数据的处理能力。
【1】 按照范围range进行相关的分区
eg: 创建一个范围的分区表保存订单的相关信息,按照订单的时间进行相关的分区存储:
sql> create table ticket (
tid number(4),tname varchar2(30),tprice number(4,2),ttime date
) partition by range(ttime)(
partition part1 values less than ('01-1 月-2008') tablespace mytemp1,partition part2 values less than ('01-1 月-2009') tablespace mytemp2,partition part3 values less than (MAXVALUE) tablespace mytemp3,);
sql> insert into part_book values (1 '买鞋','22.34','20-1 月 -2007');
sql> insert into part_book values (2 '买书','12.34','22-1 月 -2008');
sql> insert into part_book values (1 '买房','22340','2-1 月 -2017');
【2】 按照散列HASH关键字进行相关的分区
sql> create table ticket( tid number(4),tname varchar2(30),tprice number(4,2),ttime date ) partition by HASH(tid)(
partition part1 tablespace mytemp1,partition part2 tablespace mytemp2
);
【3】 按照列表list关键字进行相关的分区
eg: 创建分区表按照省份进行分区
sql> create table ticket( tid number(4),tprovince varchar2(50),ttime date ) partition by LIST(tprovince)(
partition part1 values('北京') tablespace mytemp1,partition part2 values('山东') tablespace mytemp2
);
【4】 创建组合分区表
eg:创建一个组合范围散列表,按照ttime 进行分区,再按照bid列进行散列分区
sql> create table ticket( tid number(4),ttime date ) partition by RANGE(ttime)
subpartition by HASH(tid)
subpartition2 store IN (mytemp1,mytemp2)(
partition part1 values less than('01-1月-2008')
partition part2 values less than('01-1月-2009')
);
【5】创建组合范围列表分区表
eg:创建一个组合范围列表分区表,根据ttime列进行范围分区,根据省份tprovince进行列表分区
sql> create table ticket( tid number(4),ttime date ) partition by RANGE(ttime)
subpartition by LIST(tprovince)(
partition part1 values less than('01-1 月-2008')(
subpartition part1_1 values('北京') tablespace mytemp1,subpartition part1_2 values('山东') tablespace mytemp1
),partition part2 values less than('01-1 月-2008')(
subpartition part2_1 values('北京') tablespace mytemp2,subpartition part2_2 values('山东') tablespace mytemp2
),partition part3 values less than('MAXVALUE')(
subpartition part3_1 values('北京') tablespace mytemp3,subpartition part3_2 values('山东') tablespace mytemp3
),);