1.3. 创建其他类型分区表
1.3.1. 用多列分区键创建范围分区表
SQL> create table aning_mutilcol_range
2 (aning_id number,
3 aning_name varchar2(100),
4 aning_year number,
5 aning_month number,
6 aning_day number,
7 aning_amount number
8 )
9 partition by range (aning_year,aning_month)
10 (partition mutil_range2011 values less than (2012,1),
11 partition mutil_range_1203 values less than (2012,4),
12 partition mutil_range_1205 values less than (2012,6),
13 partition mutil_range_1302 values less than (2013,3),
14 partition mutil_range_max values less than (maxvalue,0)
15 );
Table created.
插入测试数据
INSERT INTO aning_mutilcol_range VALUES(1,'aning1',2011,12,12, 1000);
INSERT INTO aning_mutilcol_range VALUES(2,'aning2',2012,3,17, 2000);
INSERT INTO aning_mutilcol_range VALUES(3,'aning3',2012,5,5, 5000);
INSERT INTO aning_mutilcol_range VALUES(4,'aning4',2013,2,2, 4000);
INSERT INTO aning_mutilcol_range VALUES(5,'aning5',2013,5,2, 6000);
commit;
查询分区表数据分布
SQL> set line 100
SQL> col ANING_NAME for a10
SQL> SELECT * FROM aning_mutilcol_range PARTITION(mutil_range2011);
ANING_ID ANING_NAME ANING_YEAR ANING_MONTH ANING_DAY ANING_AMOUNT
---------- ---------- ---------- ----------- ---------- ------------
1 aning1 2011 12 12 1000
SQL>
SQL> SELECT * FROM aning_mutilcol_range PARTITION(mutil_range_1203);
ANING_ID ANING_NAME ANING_YEAR ANING_MONTH ANING_DAY ANING_AMOUNT
---------- ---------- ---------- ----------- ---------- ------------
2 aning2 2012 3 17 2000
SQL>
SQL> SELECT * FROM aning_mutilcol_range PARTITION(mutil_range_1205);
ANING_ID ANING_NAME ANING_YEAR ANING_MONTH ANING_DAY ANING_AMOUNT
---------- ---------- ---------- ----------- ---------- ------------
3 aning3 2012 5 5 5000
SQL>
SQL> SELECT * FROM aning_mutilcol_range PARTITION(mutil_range_1205);
ANING_ID ANING_NAME ANING_YEAR ANING_MONTH ANING_DAY ANING_AMOUNT
---------- ---------- ---------- ----------- ---------- ------------
3 aning3 2012 5 5 5000
SQL>
SQL> SELECT * FROM aning_mutilcol_range PARTITION(mutil_range_max);
ANING_ID ANING_NAME ANING_YEAR ANING_MONTH ANING_DAY ANING_AMOUNT
---------- ---------- ---------- ----------- ---------- ------------
5 aning5 2013 5 2 6000
SQL>
1.3.2. 基于虚拟列创建分区表
使用虚拟列做为子分区键值
SQL> create table aning_virtual_col
2 (aning_id number,
3 aning_name varchar2(100),
4 aning_date date,
5 aning_quantity number,
6 aning_amount number,
7 aning_total as (aning_quantity * aning_amount)
8 )
9 partition by range(aning_date) interval (numtoyminterval(1,'month'))
10 subpartition by range (aning_total)
11 subpartition template
12 (subpartition vircol_small values less than (1000),
13 subpartition vircol_medium values less than (5000),
14 subpartition vircol_large values less than (10000),
15 subpartition vircol_max values less than (maxvalue)
16 )
17 (partition vircol2010 values less than (to_date('2011-01-01','yyyy-mm-dd'))
18 )
19 enable row movement
20 parallel nologging;
Table created.