Oracle 表分區

create table tb1
(
  iD int,
  tb_name varchar2(10),
  tb_date date,
  constraint pk primary key(id)
  using index tablespace tbs_1
)
partition by range(tb_date)
(
  partition part1 values less than(to_date('2013-1-1','YYYY-MM-DD')) tablespace tbs_2
  partition part2 values less than(maxvalue) tablespace tbs_3
);


create table tb2
(
  iD int,
  tb_area varchar2(10),
  tb_date date
)
partition by list(tb_area)
(
  partition part1 values('北京') tablespace tbs_1,
  partition part2 values('上海') tablespace tbs_2 
); 


drop table tb2;


insert into tb2
select 1,'北京',to_date('2013-6-1','YYYY-MM-DD')
from dual
union all
select 2,'上海',to_date('2013-12-1','YYYY-MM-DD') 
from dual
union all
select 3,'北京',to_date('2013-2-21','YYYY-MM-DD') 
from dual
union all
select 4,'北京',to_date('2013-9-1','YYYY-MM-DD') 
from dual;


select * from tb2;
select * from tb2 partition(part1);
select * from tb2 partition(part2);

組合分區:
create table graderecord
(   
  sno varchar2(10),   
  sname varchar2(20),   
  dormitory varchar2(3),   
  grade int  
)   
partition by range(grade)   
subpartition by hash(sno,sname)   
(   
  partition part1 values less than(75)   
            (   
               subpartition spart1 tablespace tbs_1,subpartition spart2 tablespace tbs_2
            ),
  partition part2 values less than(maxvalue)   
            (   
               subpartition spart3 tablespace tbs_1,subpartition spart4 tablespace tbs_2
            )
);  


drop table graderecord;




insert into graderecord values('511601','魁','229',92);   
insert into graderecord values('511602','凱','229',62);   
insert into graderecord values('511603','東','229',26);   
insert into graderecord values('511604','亮','228',77);   
insert into graderecord values('511605','敬','228',47);   
insert into graderecord values('511607','明','240',90);   
insert into graderecord values('511608','楠','240',100);   
insert into graderecord values('511609','濤','240',67);   
insert into graderecord values('511610','博','240',75);   
insert into graderecord values('511611','錚','240',60);   
insert into graderecord values('511612','狸','244',72);   
insert into graderecord values('511613','傑','244',88);   
insert into graderecord values('511614','萎','244',19);   
insert into graderecord values('511615','猥','244',65);   
insert into graderecord values('511616','丹','244',59);   
insert into graderecord values('511617','靳','244',95);  




select * from graderecord partition(part1);
select * from graderecord partition(part2);
select * from graderecord subpartition(spart1);
發佈了34 篇原創文章 · 獲贊 16 · 訪問量 3萬+
發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章