本文共 1913 字,大约阅读时间需要 6 分钟。
转自:
ORACLE11g的表分区功能中可以建立新类型的Interval分区表,它可以根据加载数据,自动创建指定间隔的分区,也就是说建立了Interval分区 ,就不必像ORACLE10以前的表分区那样需要提前为新数据建立分区,它会自动创建,以下是创建的语句。注意其中INTERVAL后面指定的关键词,对于月与天是不同的,具体已经标注出来。
按年分区:
CREATE TABLE TEST_PART(TIME_ID NUMBER,REGION_ID NUMBER,ORDER_ID NUMBER,ORDER_DATE DATE)PARTITION BY RANGE (ORDER_DATE)INTERVAL (NUMTOYMINTERVAL(1,'year')(PARTITION part1VALUES LESS THAN (TO_DATE ('2013-06-01', 'YYYY-MM-DD')),PARTITION part2VALUES LESS THAN (TO_DATE ('2014-06-01', 'YYYY-MM-DD')))按月分区:
CREATE TABLE TEST_PART(TIME_ID NUMBER,REGION_ID NUMBER,ORDER_ID NUMBER,ORDER_DATE DATE)PARTITION BY RANGE (ORDER_DATE)INTERVAL (NUMTOYMINTERVAL(1,’month’)(PARTITION part1VALUES LESS THAN (TO_DATE ('2013-06-01', 'YYYY-MM-DD')),PARTITION part2VALUES LESS THAN (TO_DATE ('2013-07-01', 'YYYY-MM-DD')))按周分区:
CREATE TABLE TEST_PART
(TIME_ID NUMBER,REGION_ID NUMBER,ORDER_ID NUMBER,ORDER_DATE DATE)INTERVAL ( NUMTODSINTERVAL (7, 'day') )(PARTITION part1VALUES LESS THAN (TO_DATE ('2013-06-01', 'YYYY-MM-DD')),PARTITION part2VALUES LESS THAN (TO_DATE ('2013-06-08', 'YYYY-MM-DD')))按天分区:
CREATE TABLE TEST_PART
(TIME_ID NUMBER,REGION_ID NUMBER,ORDER_ID NUMBER,ORDER_DATE DATE)INTERVAL ( NUMTODSINTERVAL (1, 'day') )(PARTITION part1VALUES LESS THAN (TO_DATE ('2013-06-01', 'YYYY-MM-DD')),PARTITION part2VALUES LESS THAN (TO_DATE ('2013-06-02', 'YYYY-MM-DD')))这两个关键词的不同之处 在于:
numtodsinterval(<x>,<c>) ,x是一个数字,c是一个字符串,
表明x的单位,这个函数把x转为interval day to second数据类型
常用的单位有 ('day','hour','minute','second')exampleSQL> select sysdate,sysdate+numtodsinterval(3,'hour') as res from dual;SYSDATE RES2007-09-05 01:45:34 2007-09-05 04:45:34
numtoyminterval 与numtodsinterval函数类似,将x转为interval year to month数据类型常用的单位有'year','month'exampleSQL> select sysdate,sysdate+numtoyminterval(3,'year') as res from dual;SYSDATE RES2007-09-05 01:54:53 2010-09-05 01:54:53
转载于:https://blog.51cto.com/291268154/2149102