Code Snippet

Just another Code Snippet site

[Oralce] Table partitioned by Date interval

CREATE TABLE TBL_1 (
  ID                  NUMBER                NOT NULL,
  REQ_TIMESTAMP       DATE                  NOT NULL,
  ...
)
PARTITION BY 
RANGE ( REQ_TIMESTAMP )
INTERVAL(NUMTODSINTERVAL(1, 'DAY'))
STORE IN (TBLSP1, TBLSP2, TBLSP3, TBLSP4, TBLSP5)
(  
   -- Default partition -- 
   PARTITION PART_0 VALUES LESS THAN (TO_DATE('01-01-2010', 'DD-MM-YYYY')) 
);

Data will be spread over 5 different tablespaces using a “round robin” method.
A new partition will be created for each interval (in this case, 1 DAY).

To remove a partition :

ALTER table TBL_1 drop partition for ( to_date('01/01/2015', 'DD/MM/YYYY') );


Leave a Reply

Your email address will not be published. Required fields are marked *