ORACLE数据库中PARTITION的用法.docx
文本预览下载声明
Oracle9i通过引入列表分区(List Partition),使得当前共有4种分区数据的方法,具体列出如下: 第一种范围分区 1 对表进行单列的范围分区: 这使最为常用也是最简单的方法,具体例子如下: create table emp (empno number(4), ename varchar2(30), sal number) partition by range(empno) (partition e1 s less than (1000) tablespace emp1, partition e2 s less than (2000) tablespace emp2, partition e3 s less than (max) tablespace emp3); insert into emp s (100,Tom,1000); insert into emp s (500,Peter,2000); insert into emp s (1000,Scott,3000); insert into emp s (1999,Bill,4000); insert into emp s (5000,Gates,6000); commit; 从emp表中选择全部的纪录如下: SQL select * from emp; EMPNO ENAME SAL ---------- ------------------------------ ---------- 100 Tom 1000 500 Peter 2000 1000 Scott 3000 1999 Bill 4000 5000 Gates 6000 还可以按照分区进行选择: SQL select * from emp partition (e1); EMPNO ENAME SAL ---------- ------------------------------ ---------- 100 Tom 1000 500 Peter 2000 SQL select * from emp partition (e2) EMPNO ENAME SAL ---------- ------------------------------ ---------- 1000 Scott 3000 1999 Bill 4000 SQL select * from emp partition (e3) EMPNO ENAME SAL ---------- ------------------------------ ---------- 5000 Gates 6000 使用了分区,还可以单独针对指定的分区进行truncate操作: alter table emp truncate partition e2; 2 对表进行多列的范围分区: 多列的范围分区主要是基于表中多个列的值的范围对数据进行分区,例如: drop table emp; create table emp (empno number(4), ename varchar2(30), sal number, day integer not null, month integer not null) partition by range(month,day) (partition e1 s less than (5,1) tablespace emp1, partition e2 s less than (10,2) tablespace emp2, partition e3 s less than (max,max) tablespace emp3); SQL insert into emp s (100,Tom,1000,10,6); SQL insert into emp s (200,Peter,2000,3,1); SQL insert into emp s (300,Jane,3000,23,11); 第二种 Hash分区: hash分区最主要的机制是根据hash算法来计算具体某条纪录应该插入到哪个分区中 (问:hash算法是干什么的?呵呵,只能去看看数据结构了) hash算法中最重要的是hash函数,Oracle中如果你要使用hash分区,只需指定分区的数量即可 建议分区的数量采用2的n次方,这样可以使得各个分区间数据分布更加均匀 具体例子如下
显示全部