我要做的是创建一个具有复合范围分区的表 - 按月分区和按日分区分在同一分区键上。
我已尝试使用maxvalue或day interval来进行子分区,但它仍然不起作用,我的想法不合适。分区范围是2年,所以代码很长。我有一个分区范围的片段。
PARTITION BY RANGE (SCL_DATE) INTERVAL (NUMTOYMINTERVAL(1, 'MONTH'))
SUBPARTITION BY RANGE(SCL_DATE)
(
PARTITION JAN14 VALUES LESS THAN (TO_DATE('01/02/2014', 'DD/MM/YYYY'))
(
SUBPARTITION JAN14_1 VALUES LESS THAN(TO_DATE('01/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_2 VALUES LESS THAN(TO_DATE('02/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_3 VALUES LESS THAN(TO_DATE('03/01/2014', 'DD/MM/YYYY')),
PARTITION JAN14_4 VALUES LESS THAN(TO_DATE('04/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_5 VALUES LESS THAN(TO_DATE('05/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_6 VALUES LESS THAN(TO_DATE('06/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_7 VALUES LESS THAN(TO_DATE('07/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_8 VALUES LESS THAN(TO_DATE('08/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_9 VALUES LESS THAN(TO_DATE('09/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_10 VALUES LESS THAN(TO_DATE('10/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_11 VALUES LESS THAN(TO_DATE('11/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_12 VALUES LESS THAN(TO_DATE('12/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_13 VALUES LESS THAN(TO_DATE('13/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_14 VALUES LESS THAN(TO_DATE('14/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_15 VALUES LESS THAN(TO_DATE('15/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_16 VALUES LESS THAN(TO_DATE('16/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_17 VALUES LESS THAN(TO_DATE('17/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_18 VALUES LESS THAN(TO_DATE('18/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_19 VALUES LESS THAN(TO_DATE('19/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_20 VALUES LESS THAN(TO_DATE('20/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_21 VALUES LESS THAN(TO_DATE('21/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_22 VALUES LESS THAN(TO_DATE('22/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_23 VALUES LESS THAN(TO_DATE('23/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_24 VALUES LESS THAN(TO_DATE('24/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_25 VALUES LESS THAN(TO_DATE('25/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_26 VALUES LESS THAN(TO_DATE('26/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_27 VALUES LESS THAN(TO_DATE('27/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_28 VALUES LESS THAN(TO_DATE('28/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_29 VALUES LESS THAN(TO_DATE('29/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_30 VALUES LESS THAN(TO_DATE('30/01/2014', 'DD/MM/YYYY')),
SUBPARTITION JAN14_31 VALUES LESS THAN(TO_DATE('31/01/2014', 'DD/MM/YYYY'))
),
答案 0 :(得分:1)
我认为按日和按子分区按分区进行分区并不重要。只需按月(或按日,根据您的需要)进行分区。
无论如何,这个SQL应该可以工作:
CREATE TABLE THE_TABLE
(
SCL_DATE TIMESTAMP(0),
SCL_DAY NUMBER GENERATED ALWAYS AS (EXTRACT(DAY FROM SCL_DATE)) VIRTUAL,
... more COLUMNS
)
PARTITION BY RANGE (SCL_DATE) INTERVAL (INTERVAL '1' MONTH)
SUBPARTITION BY LIST ( SCL_DAY )
SUBPARTITION TEMPLATE
(SUBPARTITION P01 VALUES (1),
SUBPARTITION P02 VALUES (2),
SUBPARTITION P03 VALUES (3),
...
SUBPARTITION P30 VALUES (30)
SUBPARTITION P31 VALUES (31)
)
(
PARTITION P_201401 VALUES LESS THAN (TIMESTAMP '2014-01-01 00:00:00')
);