oracle10g创建分区表
进阶练习 7:分区背景:认识分区,会使用表分区和索引分区(参考官方文档)。整个练习使用dba_objects作为数据源。
任务1. 创建一张表,以dba_objects数据为基础的表,使用范围分区的方法,在CREATED字段上进行分区,要求表的分区在不同的表空间上;以及相应的本地分区索引。
创建表空间:SQL> create tablespace tbs_created1 datafile'/oracle/oradata/orcl/test/tbs_created1_01.dbf' size 100M;SQL> create tablespace tbs_created2 datafile'/oracle/oradata/orcl/test/tbs_created2_01.dbf' size 100M;SQL> create tablespace tbs_created3 datafile'/oracle/oradata/orcl/test/tbs_created3_01.dbf' size 100M;SQL> create tablespace tbs_created4 datafile'/oracle/oradata/orcl/test/tbs_created4_01.dbf' size 100M;
修改系统时间格式:alter session set NLS_DATE_FORMAT='yyyy-mm-dd hh24:mi:ss';
创建分区表:SQL> create table test_part_range partition by range(CREATED)(partition p1 values less than ('2012-08-14 00:00:00') tablespace tbs_created1,partition p2 values less than ('2012-08-24 00:00:00') tablespace tbs_created2,partition p3 values less than ('2012-08-29 00:00:00') tablespace tbs_created3,partition p4 values less than (maxvalue) tablespace tbs_created4)as select * from dba_objects where 1=2;
查看段信息:select SEGMENT_NAME,PARTITION_NAME from user_segments whereSEGMENT_NAME='TEST_PART_RANGE';
向分区表插入数据:insert into test_part_range select * from dba_objects;
查看dba_objects视图中的个数:select count(*) from dba_objects;
查看每个分区的记录数:SQL> select count(*) from test_part_range partition(p1)union allselect count(*) from test_part_range partition(p2)union allselect count(*) from test_part_range partition(p3)union allselect count(*) from test_part_range partition(p4);
创建本地索引:create index test_index on test_part_range(CREATED) LOCAL(partition p1,partition p2,partition p3,partition p4);
2. 创建一张表,以dba_objects数据为基础的表,使用hash分区的方法,在object_id字段上进行分区,要求表的分区在不同的表空间上。
创建表空间:SQL> create tablespace tbs_hash1 datafile'/oracle/oradata/orcl/test/tbs_hash1_01.dbf' size 50M;SQL> create tablespace tbs_hash2 datafile'/oracle/oradata/orcl/test/tbs_hash2_01.dbf' size 50M;SQL> create tablespace tbs_hash3 datafile'/oracle/oradata/orcl/test/tbs