范围分区、hash 分区、列表分区的搭建
 
一范围分区表(需有严格的范围划分条件)
因为分区表的特征就是一个表对应多个表空间,所以,先建出多个表空间
create tablespace ts01 logging datafile '/oracle/app/oradata/test/ts01.dbf' size 10m;
 
create tablespace ts02 logging datafile '/oracle/app/oradata/test/ts02.dbf' size 10m;
 
create tablespace ts03 logging datafile '/oracle/app/oradata/test/ts03.dbf' size 10m;
 
create tablespace ts04 logging datafile '/oracle/app/oradata/test/ts04.dbf' size 10m;
查看
 

oracle三种分区表的建立_oracle

创建分区表:
SQL> create table test123(id number,createdate date) partition by range(createdate)(partition p1 values less than (to_date('2001-01-01','yyyy-mm-dd')) tablespace ts01,partition p2 values less than (to_date('2002-01-01','yyyy-mm-dd')) tablespace ts02,partition p3 values less than (to_date('2003-01-01','yyyy-mm-dd')) tablespace ts03, partition pmax values less than (maxvalue) tablespace ts04);
 
partition by range(createdate):以创建时间这一列做范围分区表
 
插入数据:
SQL> insert into test123 values(12,to_date('2002-02-02','yyyy-mm-dd'));
多一些效果明显
SQL> insert into test123 select * from test123;
 

oracle三种分区表的建立_oracle_02

 
hash分区表:
SQL> create table test321 (id number,name varchar2(10))
    partition by hash(name)
    partitions 4
    store in (ts01,ts02,ts03,ts04);通过算法自己存储
同样插入数据:
SQL> insert into test321 values(1,'bing');
SQL> insert into test321 values(23,'haha');
SQL> insert into test321 values(57,'heihei');
SQL> insert into test321 values(723,'nimei');
SQL> insert into test321 values(1001,'kengdie');
SQL> insert into test321 select * from test321;
 

oracle三种分区表的建立_oracle_03

通过上图,可以看出,数据是不规则的加载到数据文件中的
 
 
三列表分区:
该分区的特点是某列的值只有几个,基于这样的特点我们可以采用列表分区。
比如城市,省份
 
SQL> create table test100 (id number,name varchar2(20),city varchar2(20))partition by list(city)(partition p1 values('beijing','shanghai') tablespace ts01,partition p2 values('tianjin','chongqing') tablespace ts02,partition p3 values('chengde','zhangjiakou') tablespace ts03,partition p4 values(default) tablespace ts04);
同样插入数据:
SQL> insert into test100 values(1,'laoli','beijing');
SQL> insert into test100 values(2,'zhangsan','chengde');
可以看出是TS01和TS03增加了
 

oracle三种分区表的建立_oracle_04

OK!!!O(∩_∩)O~~