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;
  (转载自http://www.blogjava.net/improviser/archive/2007/10/01/150073.html
原文地址:https://www.cnblogs.com/linsond/p/1543818.html