在Oracle 9iR2及以后版本中,可以先按区间对表分区然后在每个区间分区中,再按列表或散列进行分区。从11gR1开始,已经从2个组合机
大家好!
今天整理了10g 11g所有分区表创建的方法示例,在这里和大家分享下:
1.1 9i、10g、11gR1、11gR2支持分区情况
区间 列表 散列
区间 11gR1 9iR2 9iR2
列表 11gR1 11gR1 11gR1
散列 11gR2 11gR2 11gR2
注:在Oracle 9iR2及以后版本中,可以先按区间对表分区然后在每个区间分区中,再按列表或散列进行分区。从11gR1开始,,已经从2个组合机制发展到6个。而在11gR2之后,更是有9种组合机制可以选择。
1.2. 单分区创建举例
1.2.1.创建范围分区表和全局索引
SQL> create table aning_range
2 (aning_id number,
3 aning_name varchar2(100),
4 aning_date date
5 )
6 partition by range (aning_date)
7 (
8 partition aning_p1_2010 values less than
9 (to_date('2011-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss')) tablespace aningtbs1,
10 partition aning_p2_2011 values less than
11 (to_date('2012-01-01 00:00:00','yyyy-mm-dd hh24:mi:ss')) tablespace aningtbs2,
12 partition aning_max values less than (maxvalue)
13 );
Table created.
创建enable row movement的范围分区表
SQL> create table aning_range_en_rowmove
2 (aning_id number,
3 aning_name varchar2(100),
4 aning_date date
5 )
6 storage (initial 100k next 50k) logging
7 partition by range (aning_date)
8 (partition aning_p1_2010 values less than
9 (to_date('2011-01-01','yyyy-mm-dd')) tablespace aningtbs1 storage (initial 20k next 10k),
10 partition aning_p2_2011 values less than
11 (to_date('2012-01-01','yyyy-mm-dd')) tablespace aningtbs2,
12 partition aning_max values less than (maxvalue)
13 )
14 enable row movement;
Table created.
创建范围分区表全局索引
SQL> create index idx_aning_range on aning_range(aning_date)global;
Index created.
SQL> create index idx_aning_range_1 on aning_range(aning_id) global;
Index created.
创建索引时,后面加global也不是全局分区索引
创建全局分区索引
SQL> create index idx_aning_range_g on aning_range(aning_date,aning_id)
2 global partition by range(aning_date)
3 (partition aning_p1_2010 values less than
4 (to_date('2011-01-01','yyyy-mm-dd')) tablespace aningtbs1,
5 partition aning_p2_2011 values less than
6 (to_date('2012-01-01','yyyy-mm-dd')) tablespace aningtbs2,
7 partition aning_max values less than (maxvalue)
8 );
Index created.
测试Oracle不支持非前缀全局分区索引
SQL> create index idx_aning_range_g on aning_range(aning_id)
2 global partition by range(aning_date)
3 (partition aning_p1_2010 values less than
4 (to_date('2011-01-01','yyyy-mm-dd')) tablespace aningtbs1,
5 partition aning_p2_2011 values less than
6 (to_date('2011-01-01','yyyy-mm-dd')) tablespace aningtbs2,
7 partition aning_max values less than (maxvalue)
8 );
global partition by range(aning_date)
*
ERROR at line 2:
ORA-14038: GLOBAL partitioned index must be prefixed
这里的前缀是指创建分区索引时的索引分区键