Oracle之分区表

Posted 纸短情长,伏惟珍重.

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了Oracle之分区表相关的知识,希望对你有一定的参考价值。

CREATE TABLE table_name
( 
xx NUMBER(16,0) NOT NULL ENABLE, 
tiems date
PRIMARY KEY ( XH )
)

partition by range (tiems)
subpartition by range (tiems)
(
partition P1 values less than (TO_DATE(‘2016-12-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘))
(
SUBPARTITION P1SUB1 VALUES LESS THAN(TO_DATE(‘2016-1-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P1SUB2 VALUES LESS THAN(TO_DATE(‘2016-2-28 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P1SUB3 VALUES LESS THAN(TO_DATE(‘2016-3-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P1SUB4 VALUES LESS THAN(TO_DATE(‘2016-4-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)) ,
SUBPARTITION P1SUB5 VALUES LESS THAN(TO_DATE(‘2016-5-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P1SUB6 VALUES LESS THAN(TO_DATE(‘2016-6-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P1SUB7 VALUES LESS THAN(TO_DATE(‘2016-7-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P1SUB8 VALUES LESS THAN(TO_DATE(‘2016-8-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P1SUB9 VALUES LESS THAN(TO_DATE(‘2016-9-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P1SUB10 VALUES LESS THAN(TO_DATE(‘2016-10-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P1SUB11 VALUES LESS THAN(TO_DATE(‘2016-11-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P1SUB12 VALUES LESS THAN(TO_DATE(‘2016-12-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘))
),
partition P2 values less than (TO_DATE(‘2017-12-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘))
(
SUBPARTITION P2SUB1 VALUES LESS THAN(TO_DATE(‘2017-1-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P2SUB2 VALUES LESS THAN(TO_DATE(‘2017-2-28 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P2SUB3 VALUES LESS THAN(TO_DATE(‘2017-3-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P2SUB4 VALUES LESS THAN(TO_DATE(‘2017-4-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)) ,
SUBPARTITION P2SUB5 VALUES LESS THAN(TO_DATE(‘2017-5-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P2SUB6 VALUES LESS THAN(TO_DATE(‘2017-6-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P2SUB7 VALUES LESS THAN(TO_DATE(‘2017-7-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P2SUB8 VALUES LESS THAN(TO_DATE(‘2017-8-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P2SUB9 VALUES LESS THAN(TO_DATE(‘2017-9-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P2SUB10 VALUES LESS THAN(TO_DATE(‘2017-10-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P2SUB11 VALUES LESS THAN(TO_DATE(‘2017-11-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P2SUB12 VALUES LESS THAN(TO_DATE(‘2017-12-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘))
),
partition P3 values less than (TO_DATE(‘2018-12-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘))
(
SUBPARTITION P3SUB1 VALUES LESS THAN(TO_DATE(‘2018-1-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P3SUB2 VALUES LESS THAN(TO_DATE(‘2018-2-28 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P3SUB3 VALUES LESS THAN(TO_DATE(‘2018-3-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P3SUB4 VALUES LESS THAN(TO_DATE(‘2018-4-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)) ,
SUBPARTITION P3SUB5 VALUES LESS THAN(TO_DATE(‘2018-5-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P3SUB6 VALUES LESS THAN(TO_DATE(‘2018-6-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P3SUB7 VALUES LESS THAN(TO_DATE(‘2018-7-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P3SUB8 VALUES LESS THAN(TO_DATE(‘2018-8-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P3SUB9 VALUES LESS THAN(TO_DATE(‘2018-9-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P3SUB10 VALUES LESS THAN(TO_DATE(‘2018-10-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P3SUB11 VALUES LESS THAN(TO_DATE(‘2018-11-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P3SUB12 VALUES LESS THAN(TO_DATE(‘2018-12-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘))
),
partition P4 values less than (TO_DATE(‘2018-12-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘))
(
SUBPARTITION P4SUB1 VALUES LESS THAN(TO_DATE(‘2019-1-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P4SUB2 VALUES LESS THAN(TO_DATE(‘2019-2-28 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P4SUB3 VALUES LESS THAN(TO_DATE(‘2019-3-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P4SUB4 VALUES LESS THAN(TO_DATE(‘2019-4-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)) ,
SUBPARTITION P4SUB5 VALUES LESS THAN(TO_DATE(‘2019-5-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P4SUB6 VALUES LESS THAN(TO_DATE(‘2019-6-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P4SUB7 VALUES LESS THAN(TO_DATE(‘2019-7-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P4SUB8 VALUES LESS THAN(TO_DATE(‘2019-8-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P4SUB9 VALUES LESS THAN(TO_DATE(‘2019-9-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P4SUB10 VALUES LESS THAN(TO_DATE(‘2019-10-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P4SUB11 VALUES LESS THAN(TO_DATE(‘2019-11-30 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘)),
SUBPARTITION P4SUB12 VALUES LESS THAN(TO_DATE(‘2019-12-31 00:00:00‘, ‘yyyy-mm-dd hh24:mi:ss‘))
)
)

  创建分区表,并且为其创建分区和子分区

以上是关于Oracle之分区表的主要内容,如果未能解决你的问题,请参考以下文章

Oracle之分区表

没索引oracle无唯一索引交换分区会丢失数据?

Oracle提升查询性能之-简单范围分区表的创建

Oracle Spatial分区应用研究之二:按县分区与按省分区对比测试报告

Oracle Spatial分区应用研究之三:县市省不同分区粒度的效率比较

Oracle Spatial分区应用研究之四:不同分区粒度+全局空间索引效率对比