oracle分区实例 下载本文

partition p_0705_013 values less than('200705','014'), partition p_0705_014 values less than('200705','015'), partition p_0705_015 values less than('200705','016'), partition p_0706_010 values less than('200706','011'), partition p_0706_011 values less than('200706','012'), partition p_0706_012 values less than('200706','013'), partition p_0706_013 values less than('200706','014'), partition p_0706_014 values less than('200706','015'), partition p_0706_015 values less than('200706','016'), partition p_0707_010 values less than('200707','011'), partition p_0707_011 values less than('200707','012'), partition p_0707_012 values less than('200707','013'), partition p_0707_013 values less than('200707','014'), partition p_0707_014 values less than('200707','015'), partition p_0707_015 values less than('200707','016'), partition p_0708_010 values less than('200708','011'), partition p_0708_011 values less than('200708','012'), partition p_0708_012 values less than('200708','013'), partition p_0708_013 values less than('200708','014'), partition p_0708_014 values less than('200708','015'), partition p_0708_015 values less than('200708','016'), partition p_0709_010 values less than('200709','011'), partition p_0709_011 values less than('200709','012'), partition p_0709_012 values less than('200709','013'), partition p_0709_013 values less than('200709','014'), partition p_0709_014 values less than('200709','015'), partition p_0709_015 values less than('200709','016'), partition p_0710_010 values less than('200710','011'), partition p_0710_011 values less than('200710','012'), partition p_0710_012 values less than('200710','013'), partition p_0710_013 values less than('200710','014'), partition p_0710_014 values less than('200710','015'), partition p_0710_015 values less than('200710','016'), partition p_0711_010 values less than('200711','011'), partition p_0711_011 values less than('200711','012'), partition p_0711_012 values less than('200711','013'), partition p_0711_013 values less than('200711','014'), partition p_0711_014 values less than('200711','015'), partition p_0711_015 values less than('200711','016'), partition p_0712_010 values less than('200712','011'), partition p_0712_011 values less than('200712','012'), partition p_0712_012 values less than('200712','013'), partition p_0712_013 values less than('200712','014'), partition p_0712_014 values less than('200712','015'),

partition p_0712_015 values less than('200712','016'), partition p_0801_010 values less than('200801','011'), partition p_0801_011 values less than('200801','012'), partition p_0801_012 values less than('200801','013'), partition p_0801_013 values less than('200801','014'), partition p_0801_014 values less than('200801','015'), partition p_0801_015 values less than('200801','016'), partition p_other values less than(maxvalue, maxvalue) );

这个是带有模板子分区的,模板子分区详细到月中的天。这种分区模式只要建立了分区就会自动创建子分区的。

插入上面不带模板分区实验相同的数据,随机查询分区数据:

查询分区p_0701_010的数据:

Sql代码:

select * from MobileMessage partition(p_0701_010); 查询结果:

查询子分区p_0701_010_sub4的数据:

Sql代码:

select * from MobileMessage subpartition(p_0701_010_sub4); 查询结果如下:

查询分区p_0706_011的数据: Sql代码:

select * from MobileMessage partition(p_0706_011); 查询结果如下:

查询子分区p_0706_011_sub21的数据: Sql代码:

select * from MobileMessage subpartition(p_0706_011_sub21); 查询结果如下:

下面讲讲分区的维护操作:

(1)分裂分区,以第一个范围分区为例: Sql代码:

alter table graderecord split partition jige at(75) into(partition keyi,partition lianghao); 把分区及格分裂为两个分区:可以和良好。

(2)合并分区,以第一个范围分区为例:

Sql代码:

alter table graderecord merge partitions keyi,lianghao into partition jige;

把可以和良好两个分区合并为及格。

(3)添加分区,由于在范围分区上添加分区要求添加的分区范围大于原有分区最大值,但原有分区最大值已经为maxvalue,故本处以第二个散列分区为例:

Sql代码:

alter table graderecord add partition p4; 给散列分区例子又增加了一个分区p4 。

(4)删除分区,语法: Sql代码:

alter table table_name drop partition partition_name;

(5)截断分区,清空分区中的数据:

Sql代码:

alter table table_name truncate partition partition_name;

说明:对待分区的操作同样可以对待子分区,效果一样。删除一个分区会同时删除其下的子分区。合并多个分区也会把他们的子分区自动合并。分裂分区时注意分裂点。

另外不带模板子分区和带有模板子分区的分区表操作的区别:带有子分区模板的分区表在添加分区时候自动添加子分区,不带模板子分区的分区表没有这个功能;带有子分区模板的分区表在更改分区时只需更改分区,不带模板子分区的分区表在更改分区时一定注意连同子分区一起更改。