Oracle表分区总结

Oracle中提供了对表进行分区的机制,通过表分区,可以将表空间中数据按照某种方式分别存放到特定的分区中。表分区的作用:平衡IO操作,分区均匀,提高效率。

Oracle中表分区方法有:范围分区法、散列分区法、复合分区法、列表分区法。

范围分区:
语法
Partition by range(); 适合数值型或日期型
示例:

1createtable Student
2
(
3Studentidintegernotnull
,
4Studentnamevarchar2(20
),
5Scoreinteger

6 )
7Partitionby
range(Score)
8
(
9Partitionp1valueslessthan(60
),
10Partitionp2valueslessthan(75
),
11Partitionp3valueslessthan(85
),
12Partitionp4values
lessthan(maxvalue)
13 );



散列分区法:根据Oracle内部散列算法存储,语法 Partition by hash();
实例:

1createtable department
2
(
3Deptnoint
,
4Deptnamevarchar2(24
)
5
)
6Partitionby
hash(deptno)
7
(
8
Partitionp1,
9
Partitionp2
10);



复合分区法:由上面两种方法复合而成
示例:

1createtable salgrade
2
(
3gradenumber
,
4losalnumber
,
5hisalnumber

6 )
7Partitionby
range(grade)
8Subpartitionby
hash(losal,hisal)
9
(
10Partitionp1valueslessthan(10
),
11
(subpartitionsp1,subpartitionsp2),
12Partitionp2valueslessthan(20
),
13
(subpartitionsp3,subpartitionsp4)
14)



列表分区法:适合字符型 语法Partitionbylist()
实例:

1createtable customer
2
(
3custNoint
,
4custnamevarchar(20
),
5custStatevarchar(20
)
6
)
7Partitionby
list(custState)
8
(
9Partitionsaiavalues('中国','韩国','日本'
),
10PartitionEuropevalues('英国','俄国','法国'
),
11Partitionameriavalues('美国','加拿大','墨西哥'
),
12
);
13



表分区维护:

添加分区:alter table student add partition p5 values less than(120);
删除分区:alter table student drop partition p4;
截断分区:alter table student truncate partition p5;
合并分区:alter table student merge partitions p3,p4 into partition p6;

猜你喜欢

转载自duoluohua.iteye.com/blog/1924254