每月oracle分区由group_id和子分区组成

时间:2015-02-17 14:16:23

标签: oracle partitioning

我想创建一个这样的表。

create table some_data ( 
  id number(19,0),
  group_id number(19,0),
  value float,
  timestamp timestamp
);

对于此表,我希望将数据存储为

 group_id=1
    jan-2015
    feb-2015
    ...
group_id=2
    jan-2015
    feb-2015
    ...    

等等。所以我假设我必须按group_id的范围创建分区,然后按时间戳列的范围创建子分区,对吗?

所以看起来应该是这样的:

create table some_data ( 
  id number(19,0),
  group_id number(19,0),
  value float,
  timestamp timestamp
)
PARTITION BY RANGE (group_id)
SUBPARTITION BY RANGE ("TIMESTAMP") 
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
(
 PARTITION part_1 values LESS THAN (TO_DATE('01.02.2015','DD.MM.YYYY'))
 );

这是对的吗?还有一个问题:使用这个分区,如果添加了一个新的group_id,oracle会自动为新的group_id创建一个新分区,为新数据创建新的分区吗?

1 个答案:

答案 0 :(得分:1)

子分区级别不支持间隔分区:

http://docs.oracle.com/cd/E11882_01/server.112/e41084/statements_7002.htm#SQLRF54559

您可以这样定义:

create table some_data ( 
  id number(19,0),
  group_id number(19,0),
  value float,
  timestamp timestamp  -- not good naming
)
PARTITION BY RANGE ("TIMESTAMP")
INTERVAL (NUMTOYMINTERVAL(1,'MONTH'))
SUBPARTITION BY RANGE (group_id) -- it could be hash or list as well
   subpartition template(
     ...
   )
(
 PARTITION part_1 values LESS THAN (TO_DATE('01.02.2015','DD.MM.YYYY'))
);