單表自動單個分割槽欄位使用方式,請參考:《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 );