oracle表分区详解-一步一步教你oracle分区表详解
oracle表分区详解-一步一步教你oracle分区表详解
1、创建三个不同的表空间,模拟在不同磁盘上的保存不同范围的数据
create tablespace test01 datafile '/u01/app/oracle/oradata/orcl02/test01.dbf' size 500m; ---数据文件可以不再同一存储上
create tablespace test02 datafile '/u01/app/oracle/oradata/orcl02/test02.dbf' size 500m;
create tablespace test03 datafile '/u01/app/oracle/oradata/orcl02/test03.dbf' size 500m;
2、在把表建在不同的表空间上(分块存储数据文件)
create table graderecord
(
sno varchar2(10),
sname varchar2(20),
dormitory varchar2(3),
grade int
)
partition by range(grade)
(
partition bujige values less than(60) tablespace test01, --不及格,范围分区
partition jige values less than(85) tablespace test02, --及格
partition youxiu values less than(maxvalue) tablespace test03--优秀
)
3、在表里插入数据
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(sno,sname,dormitory) values('511606','峰','228');
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);
4、分别查询结果
SQL> select * from graderecord;
select * from graderecord partition(bujige);
SNO SNAME DOR GRADE
---------- -------------------- --- ----------
511603 ?? 229 26
511605 ?? 228 47
511602 ?? 229 62
511604 ?? 228 77
511609 ?? 240 67
511610 ?? 240 75
511611 ?? 240 60
511601 ?? 229 92
511606 ?? 228
511607 ?? 240 90
511608 ?? 240 100
11 rows selected.
SQL>
SNO SNAME DOR GRADE
---------- -------------------- --- ----------
511603 ?? 229 26
511605 ?? 228 47
SQL> select * from graderecord partition(jige);
SNO SNAME DOR GRADE
---------- -------------------- --- ----------
511602 ?? 229 62
511604 ?? 228 77
511609 ?? 240 67
511610 ?? 240 75
511611 ?? 240 60
SQL> select * from graderecord partition(youxiu);
SNO SNAME DOR GRADE
---------- -------------------- --- ----------
511601 ?? 229 92
511606 ?? 228
511607 ?? 240 90
511608 ?? 240 100
SQL>
看到了吧。这就是范围分区的简单例子。