Oracle 数据表之分区表

一、分区方法 

  建分区表准备:

  1,创建4个测试用的表空间,每个表空间作为一个独立分区(考虑到Oracle中分区映射的实现方式,建议将表中的分区数设置为2的乘方,以便使数据均匀分布)

        create tablespace partition1 datafile '/home/oracle/app/oradata/orcl/partition1.dbf' size 20m;         create tablespace partition2 datafile '/home/oracle/app/oradata/orcl/partition2.dbf' size 20m;         create tablespace partition3 datafile '/home/oracle/app/oradata/orcl/partition3.dbf' size 20m;         create tablespace partition4 datafile '/home/oracle/app/oradata/orcl/partition4.dbf' size 20m;        1)范围分区      范围分区就是对数据表中的某个值的范围进行分区,根据某个值的范围,决定将该数据存储在哪个分区上。如根据序号分区,根据业务记录的创建日期进行分区等(联通每个月的账单记录就用的分区表存储)。    CREATE TABLE partition_table(     kind_id number ,     id number not null,     name  varchar(100),     start_date date not null )   partition by range(kind_id) (   partition partition1 values less than(2) tablespace partition1,   partition partition2 values less than(4) tablespace partition2,   partition partition3 values less than(6) tablespace partition3,   partition partition4 values less than(maxvalue) tablespace partition4 )   插入数据   insert into partition_table values(1,1001,'haha',to_date('2012','yyyy'));   insert into partition_table values(2,1002,'sasa',to_date('2013','yyyy'));   insert into partition_table values(3,1003,'dada',to_date('2014','yyyy'));   insert into partition_table values(4,1004,'faga', to_date('2015','yyyy'));   insert into partition_table values(5,1005,'gaga',to_date('2016','yyyy'));   insert into partition_table values(6,1006,'jaja1',to_date('2017','yyyy'));   insert into partition_table values(8,1007,'kaka',to_date('2018','yyyy'));   查询数据:      不指定分区:         select * from partition_table         指定分区:         select * from partition_table partition(partition1)   更改数据:      指定分区:         update partition_table partition(partition1) t set t.name = 'kkkl'  where start_date <to_date('2015');      不指定分区         update partition_table t set t.name = 'kkkl'  where t.start_date <to_date('2015');          3)散列分区(hash分区)   create table hash_partition_table(     kind_id number ,     id number not null,     name  varchar(100),     start_date date not null ) partition by hash(kind_id)(   partition partition1 tablespace partition1;   partition partition2 tablespace partition2;   partition partition3 tablespace partition3;   partition partition4 tablespace partition4; )      4)复合分区(子分区)       具体信息见博客:https://www.cnblogs.com/CandiceW/p/10312663.html
上一篇:Oracle中临时表空间的清理


下一篇:Oracle表空间创建及表创建