单表自动单个分区字段使用方式,请参考:《Oracle12c:自动分区表》
两个分区字段时,必须一个主分区字段和一个子分区字段构成(以下代码测试是在oracle12.1版本):
1 create table tommy_test( 2 id int, 3 name varchar2(20), 4 p_city varchar2(20), 5 p_day date 6 ) 7 partition by range(p_day) interval(NUMTODSINTERVAL(1,'day')) 8 subpartition by list(p_city) 9 subpartition template 10 ( 11 subpartition p1 values('571'), 12 subpartition p2 values('572'), 13 subpartition p3 values('573') 14 ) 15 ( 16 partition sp1 values less than (to_date('2016-01-01','yyyy-MM-dd')) 17 );
备注:上边两个分区字段中p_day是主分区字段,可以自动分区;而p_city是子分区字段,而且不可以自动分区,所选值必须是子分区模版中指定的分区选项中的值。
如果oracle版本是12.2时,可以使用下边语句(在oracle12.1版本中是不允许):
1 create table anbob_t5( 2 id int, 3 name varchar2(20), 4 region varchar2(10), 5 cycle date 6 ) 7 partition by list(region) 8 subpartition by range(cycle) 9 interval 10 (numtoyminterval(1,'month')) 11 subpartition template 12 (subpartition sp1 values less than (to_date('2016-1-1','yyyy-mm-dd'))) 13 ( 14 partition p1 values('010'), 15 partition p2 values('020'), 16 partition p3 values('0311') 17 );
list-list分区
1 CREATE TABLE customers 2 ( id NUMBER 3 , name VARCHAR2(50) 4 , email VARCHAR2(100) 5 , region VARCHAR2(4) 6 , credit_rating VARCHAR2(1) 7 ) 8 PARTITION BY LIST (region) 9 SUBPARTITION BY LIST (credit_rating) 10 SUBPARTITION TEMPLATE 11 ( SUBPARTITION poor VALUES ('P') 12 , SUBPARTITION mediocre VALUES ('C') 13 , SUBPARTITION good VALUES ('G') 14 , SUBPARTITION excellent VALUES ('E') 15 ) 16 (PARTITION americas VALUES ('AMER') 17 , PARTITION emea VALUES ('EMEA') 18 , PARTITION apac VALUES ('APAC') 19 );