1 一个大学分n个年级,将年级号码进行hash求值,年级的所有学生在一个散列分区。
原理:散列分区是根据字段的hash值进行均匀分布,尽可能的实现各分区所散列的数据相等。
创建表分区:
- createtablegraderecord
- (
- gradenovarchar2(10),--年级id
- snamevarchar2(20) --学生信息
- )
- partitionbyhash(gradeno)
- (
- partition G1,
- partition G2,
- partition G3
- );
插入值:
insert into graderecord values('G1',1);
insert into graderecord values('G1',2);
insert into graderecord values('G2',1);
查询分区值:
- select * from graderecord;//全表查询(包括所有分区)
- select*fromgraderecordpartition(G1); //查询班级号为G1的分区值,注意此时不要带上单引号‘’。
- fromgraderecordpartition(G2);
- fromgraderecordpartition(G3); //此时查询G3,因为分区不存在,会报错。
修改分区:新增一个G3分区
alter table graderecord add partition G3;
一个分区插入数据的存储过程:
- creat or replace procedure test_cyb_cyb as
- begin
- declare
- i integer; --定义变量
- begin
- i := 1;
- loop
- /* 插入数据 */
- insert into tb () values ()
- /* 参数递增 */
- i := i + 1;
- /* 停止条件 */
- exit when i > 2000000;
- end loop;
- commit;
- end;
- end;
参考:http://blog.csdn.net/oyzl68/article/details/8142617