每15分钟按字段编号自动创建分区

时间:2014-10-20 10:30:17

标签: sql oracle plsql

您好我想基于作为时间戳的字段编号(每15分钟)自动创建分区: 例如:

201401010000< ---- 2014 Gen 01 00:00

201401010000<数字< 201401010015< ---- first partition

201401010016<数字< 201401010030< ----第二个分区 。 。

我已经看到这个代码每月都有一个日期:

PARTITION BY RANGE (start_date) 
INTERVAL(NUMTOYMINTERVAL(1, 'MONTH')) 
(  
PARTITION pos_data_p2 VALUES LESS THAN (TO_DATE('1-7-2007', 'DD-MM-YYYY')),
PARTITION pos_data_p3 VALUES LESS THAN (TO_DATE('1-8-2007', 'DD-MM-YYYY')) 
); 

但每15分钟就有一个数字字段?

感谢

1 个答案:

答案 0 :(得分:1)

您应该将数字类型更改为TIMESTAMP,或者添加如下虚拟列:

ALTER TABLE MY_TABLE ADD (start_date_TS  TIMESTAMP(1) GENERATED ALWAYS AS (to_timestamp(start_date, 'yyyymmddhh24mi')));

然后你可以使用这个分区条款:

PARTITION BY RANGE (start_date_TS) 
INTERVAL(INTERVAL '15' MINUTE) 
(  
PARTITION pos_data_inital VALUES LESS THAN (TIMESTAMP '2007-07-01 00:00:00'),
); 

这是一个新表的工作示例:

CREATE TABLE MY_TABLE ( 
    nome VARCHAR2 (50), 
    start_date NUMBER (12) ,
    start_date_TS TIMESTAMP(1) GENERATED ALWAYS AS (TO_TIMESTAMP(SUBSTR(start_date,1,12), 'yyyymmddhh24mi'))
)
PARTITION BY RANGE (start_date_TS) INTERVAL(INTERVAL '15' MINUTE) 
    ( PARTITION pos_data_inital VALUES LESS THAN (TIMESTAMP '2014-10-20 00:15:00') );