Oracle 11g 的 interval 分区

官方文档

Interval Partitioning

Interval partitioning is an extension of range partitioning which instructs the database to automatically create partitions of a specified interval when data inserted into the table exceeds all of the existing range partitions. You must specify at least one range partition. The range partitioning key value determines the high value of the range partitions, which is called the transition point, and the database creates interval partitions for data with values that are beyond that transition point. The lower boundary of every interval partition is the non-inclusive upper boundary of the previous range or interval partition.

For example, if you create an interval partitioned table with monthly intervals and you set the transition point at January 1, 2007, then the lower boundary for the January 2007 interval is January 1, 2007. The lower boundary for the July 2007 interval is July 1, 2007, regardless of whether the June 2007 partition was created.

You can create single-level interval partitioned tables and the following composite partitioned tables:

  • Interval-range

  • Interval-hash

  • Interval-list

  • Only one partitioning key column can be specified, and it must be of NUMBER or DATE type.

  • Interval partitioning is not supported for index-organized tables.

  • NULL values cannot be stored in the partitioning key column when using interval partitioning.

Interval partitioning supports a subset of the capabilities of range partitioning. For information about restrictions when using interval partitioning, refer to Oracle Database SQL Language Reference.

事例

建立以month_id_date 字段的分区

--建表
CREATE TABLE INTERVAL_PARTITION_TEST(
        MONTH_ID VARCHAR2(20),
        MONTH_ID_DATE DATE
)
PARTITION BY RANGE( MONTH_ID_DATE)
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
        --历史数据只到2018年
        PARTITION MONTH_ID_201801 VALUES LESS THAN (  TO_DATE('201802','YYYYMM') )
)
;


--插入测试数据
insert into interval_partition_test values('201712',to_date('201712','yyyymm'));
insert into interval_partition_test values('201812',to_date('201812','yyyymm'));
insert into interval_partition_test values('201912',to_date('201912','yyyymm'));
insert into interval_partition_test values('202101',to_date('202101','yyyymm'));
insert into interval_partition_test values('202102',to_date('202102','yyyymm'));


 

自动分区结果

--查询表里面的分区
SELECT * FROM DBA_TAB_PARTITIONS WHERE TABLE_NAME=upper('interval_partition_test');

 

执行计划

 

参考博文:https://www.cnblogs.com/hllnj2008/p/5177220.html

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
Oracle数据库分区表可以使用分区自动命名功能,这可以帮助我们更方便地管理和维护分区表。分区自动命名是指Oracle数据库根据预定义的模式自动为新分区命名。 在创建分区表时,我们可以指定分区模式。分区模式是一个包含占位符的字符串,用于指定如何为每个新分区命名。在分区表中,占位符将被替换为实际值。 例如,以下是一个使用时间作为分区键的分区表的示例: ``` CREATE TABLE sales ( sales_id NUMBER(10), sales_date DATE, amount NUMBER(10) ) PARTITION BY RANGE (sales_date) INTERVAL(NUMTOYMINTERVAL(1,'MONTH')) ( PARTITION p1 VALUES LESS THAN (TO_DATE('01-01-2017','DD-MM-YYYY')), PARTITION p2 VALUES LESS THAN (TO_DATE('01-02-2017','DD-MM-YYYY')), PARTITION p3 VALUES LESS THAN (TO_DATE('01-03-2017','DD-MM-YYYY')), PARTITION p4 VALUES LESS THAN (MAXVALUE) ); ``` 在这个例子中,我们使用了INTERVAL关键字来指定每个新分区的时间间隔。这样,在每个时间间隔结束时,Oracle数据库将自动为我们创建一个新分区。我们还使用了分区模式来指定新分区的命名方式: ``` PARTITION p1 VALUES LESS THAN (TO_DATE('01-01-2017','DD-MM-YYYY')) ``` 在这个示例中,我们使用了TO_DATE函数来指定日期,并使用了占位符“YYYY_MM”来指定新分区的名称格式。因此,第一个分区的名称将是“P_2017_01”。 如果我们希望使用其他的占位符或更复杂的命名方式,可以根据需要修改分区模式。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值