oracle表分区总结

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

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

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

1 create table Student
2(
3      Studentid integer not null,
4      Studentname varchar2(20),
5      Score integer
6)
7 Partition by range(Score)
8(
9      Partition p1 values less than(60),
10      Partition p2 values less than(75),
11      Partition p3 values less than(85),
12      Partition p4 values less than(maxvalue)
13 );


散列分区法:根据Oracle内部散列算法存储,语法 Partition by hash();
实例:
1 create table department
2 (
3      Deptno int,
4      Deptname varchar2(24)
5 )
6 Partition by hash(deptno)
7 (
8      Partition p1,
9      Partition p2
10 );


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

1 create table salgrade
2 (
3      grade number,
4      losal number,
5      hisal number
6 )
7 Partition by range(grade)
8 Subpartition by hash(losal,hisal)
9 (
10      Partition p1 values less than(10)
11        (subpartition sp1,subpartition sp2),
12      Partition p2 values less than(20)
13        (subpartition sp3,subpartition sp4)
14 )


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

1 create table customer
2 (
3      custNo int,
4      custname varchar(20),
5      custState varchar(20)
6 )
7 Partition by list(custState)
8 (
9      Partition saia values('中国','韩国','日本'),
10      Partition Europe values('英国','俄国','法国'),
11      Partition ameria values('美国','加拿大','墨西哥'),
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;
 
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值