SQL> create tablespace part01
2 datafile 'D:\ORACLE10_2\PRODUCT\10.2.0\ORADATA\KARLDB\part01.dbf' size 100M ;
Tablespace created
SQL> create tablespace part02
2 datafile 'D:\ORACLE10_2\PRODUCT\10.2.0\ORADATA\KARLDB\part02.dbf' size 100M;
Tablespace created
SQL> create tablespace part03
2 datafile 'D:\ORACLE10_2\PRODUCT\10.2.0\ORADATA\KARLDB\part03.dbf' size 100M;
Tablespace created
X column:分区依赖列(支持多个,中间以逗号分隔);
X partition:指定分区,有两种方式:
X 直接指定分区名,分区所在表空间等信息
X 只指定分区数量,和可供使用的表空间。
① 创建hash分区表
SQL> create table t_part_hash (id number(10),name varchar2(10))
2 partition by hash(id)(
3 partition t_hash_p1 tablespace part01,
4 partition t_hash_p2 tablespace part02,
5 partition t_hash_p3 tablespace part03);
Table created
SQL> create table t_part_hash_2 (id number(10),name varchar2(10))
2 partition by hash(id )
3 partitions 3 store in (part01,part02,part03);
Table created
这就是上面说的,直接指定分区数量和可供使用的表空间。
提示:这里分区数量和可供使用的表空间数量之间没有直接对应关系。分区数并不一定要等于表空间数。
要查询表的分区信息,仍然是通过user_part_tables,user_tab_partitions两个数据字典,这里不再举例
② Global索引hash分区
SQL> create index idx_part_hash_id on t_part_hash(id)
2 global partition by hash(id)
3 partitions 3 store in (part01,part02,part03);
Index created
查询索引的分区信息也仍是通过user_part_indexes、user_ind_partitions两个数据字典,不再举例。
③ 创建Local索引
SQL> create index idx_part_hash_id_local on t_part_hash_2(id) local;
Index created
④ 验证结果:
SQL> select * from user_tab_partitions
2 where table_name ='T_PART_HASH';
TABLE_NAME COMPOSITE PARTITION_NAME SUBPARTITION_COUNT HIGH_VALUE HIGH_VALUE_LENGTH PARTITION_POSITION TABLESPACE_NAME PCT_FREE PCT_USED INI_TRANS MAX_TRANS INITIAL_EXTENT NEXT_EXTENT MIN_EXTENT MAX_EXTENT PCT_INCREASE FREELISTS FREELIST_GROUPS LOGGING COMPRESSION NUM_ROWS BLOCKS EMPTY_BLOCKS AVG_SPACE CHAIN_CNT AVG_ROW_LEN SAMPLE_SIZE LAST_ANALYZED BUFFER_POOL GLOBAL_STATS USER_STATS
------------------------------ --------- ------------------------------ ------------------ -------------------------------------------------------------------------------- ----------------- ------------------ ------------------------------ ---------- ---------- ---------- ---------- -------------- ----------- ---------- ---------- ------------ ---------- --------------- ------- ----------- ---------- ---------- ------------ ---------- ---------- ----------- ----------- ------------- ----------- ------------ ----------
T_PART_HASH NO T_HASH_P1 0 0 1 PART01 10 1 255 65536 1 2147483645 YES DISABLED DEFAULT NO NO
T_PART_HASH NO T_HASH_P2 0 0 2 PART02 10 1 255 65536 1 2147483645 YES DISABLED DEFAULT NO NO
T_PART_HASH NO T_HASH_P3 0 0 3 PART03 10 1 255 65536 1 2147483645 YES DISABLED DEFAULT NO NO
查看HASH分布:
SQL> select count(*) from t_part_hash partition(t_hash_p1);
COUNT(*)
----------
234
SQL> select count(*) from t_part_hash partition(t_hash_p2);
COUNT(*)
----------
505
SQL> select count(*) from t_part_hash partition(t_hash_p3);
COUNT(*)
----------
2 datafile 'D:\ORACLE10_2\PRODUCT\10.2.0\ORADATA\KARLDB\part01.dbf' size 100M ;
Tablespace created
SQL> create tablespace part02
2 datafile 'D:\ORACLE10_2\PRODUCT\10.2.0\ORADATA\KARLDB\part02.dbf' size 100M;
Tablespace created
SQL> create tablespace part03
2 datafile 'D:\ORACLE10_2\PRODUCT\10.2.0\ORADATA\KARLDB\part03.dbf' size 100M;
Tablespace created
X column:分区依赖列(支持多个,中间以逗号分隔);
X partition:指定分区,有两种方式:
X 直接指定分区名,分区所在表空间等信息
X 只指定分区数量,和可供使用的表空间。
① 创建hash分区表
SQL> create table t_part_hash (id number(10),name varchar2(10))
2 partition by hash(id)(
3 partition t_hash_p1 tablespace part01,
4 partition t_hash_p2 tablespace part02,
5 partition t_hash_p3 tablespace part03);
Table created
SQL> create table t_part_hash_2 (id number(10),name varchar2(10))
2 partition by hash(id )
3 partitions 3 store in (part01,part02,part03);
Table created
这就是上面说的,直接指定分区数量和可供使用的表空间。
提示:这里分区数量和可供使用的表空间数量之间没有直接对应关系。分区数并不一定要等于表空间数。
要查询表的分区信息,仍然是通过user_part_tables,user_tab_partitions两个数据字典,这里不再举例
② Global索引hash分区
SQL> create index idx_part_hash_id on t_part_hash(id)
2 global partition by hash(id)
3 partitions 3 store in (part01,part02,part03);
Index created
查询索引的分区信息也仍是通过user_part_indexes、user_ind_partitions两个数据字典,不再举例。
③ 创建Local索引
SQL> create index idx_part_hash_id_local on t_part_hash_2(id) local;
Index created
④ 验证结果:
SQL> select * from user_tab_partitions
2 where table_name ='T_PART_HASH';
TABLE_NAME COMPOSITE PARTITION_NAME SUBPARTITION_COUNT HIGH_VALUE HIGH_VALUE_LENGTH PARTITION_POSITION TABLESPACE_NAME PCT_FREE PCT_USED INI_TRANS MAX_TRANS INITIAL_EXTENT NEXT_EXTENT MIN_EXTENT MAX_EXTENT PCT_INCREASE FREELISTS FREELIST_GROUPS LOGGING COMPRESSION NUM_ROWS BLOCKS EMPTY_BLOCKS AVG_SPACE CHAIN_CNT AVG_ROW_LEN SAMPLE_SIZE LAST_ANALYZED BUFFER_POOL GLOBAL_STATS USER_STATS
------------------------------ --------- ------------------------------ ------------------ -------------------------------------------------------------------------------- ----------------- ------------------ ------------------------------ ---------- ---------- ---------- ---------- -------------- ----------- ---------- ---------- ------------ ---------- --------------- ------- ----------- ---------- ---------- ------------ ---------- ---------- ----------- ----------- ------------- ----------- ------------ ----------
T_PART_HASH NO T_HASH_P1 0 0 1 PART01 10 1 255 65536 1 2147483645 YES DISABLED DEFAULT NO NO
T_PART_HASH NO T_HASH_P2 0 0 2 PART02 10 1 255 65536 1 2147483645 YES DISABLED DEFAULT NO NO
T_PART_HASH NO T_HASH_P3 0 0 3 PART03 10 1 255 65536 1 2147483645 YES DISABLED DEFAULT NO NO
查看HASH分布:
SQL> select count(*) from t_part_hash partition(t_hash_p1);
COUNT(*)
----------
234
SQL> select count(*) from t_part_hash partition(t_hash_p2);
COUNT(*)
----------
505
SQL> select count(*) from t_part_hash partition(t_hash_p3);
COUNT(*)
----------
261
分区表及分区索引(1)--前言
分区表及分区索引(2)--创建range分区
分区表及分区索引(3)--创建hash分区
分区表及分区索引(4)--创建list分区
分区表及分区索引(5)--创建range-hash组合分区
分区表及分区索引(6)--创建range-list组合分区
分区表及分区索引(7.1)--怎样管理
分区表及分区索引(7.2)--怎样管理
分区表及分区索引(8)--增加和收缩表分区
分区表及分区索引(9)--删除表分区
分区表及分区索引(10)--交换分区
分区表及分区索引(11)--合并表分区
分区表及分区索引(12)--修改list表分区
分区表及分区索引(13)--分隔表分区
分区表及分区索引(14)--截断、移动和重命名
分区表及分区索引(15)--修改表分区属性和模板
分区表及分区索引(16)--增加和删除索引分区
分区表及分区索引(17)--其它索引分区管理操作
分区表及分区索引(18)--结束语