間隔分區是Oracle 11g第一版本添加功能。間隔分區以一個分區爲起點,根據定義的間隔,讓數據自動增加分區。
這樣varchar類型的無法作爲分區鍵值
create table interval_example
(starttime date,
name varchar2(20)
)
partition by range (starttime)
interval(numtoyminterval(1,'month'))
store in(example,learn)
(partition part1 values less than(to_date('2013-12-19','YYYY-MM-DD')));
查詢分區
SQL> select t.partition_name from dba_tab_partitions t where t.table_owner=user and t.table_name=upper('interval_example');
PARTITION_NAME
------------------------------
PART1
SQL> insert into interval_example values(to_date('2013-2-4','YYYY-MM-DD'),2);
已創建 1 行。
SQL> commit;
提交完成。
SQL> select t.partition_name from dba_tab_partitions t where t.table_owner=user and t.table_name=upper('interval_example');
PARTITION_NAME
------------------------------
PART1
SQL> select t.partition_name from dba_tab_partitions t where t.table_owner=user and t.table_name=upper('interval_example');
PARTITION_NAME
------------------------------
PART1
SQL> insert into interval_example values(to_date('2014-1-4','YYYY-MM-DD'),2);
已創建 1 行。
SQL> select t.partition_name from dba_tab_partitions t where t.table_owner=user and t.table_name=upper('interval_example');
PARTITION_NAME
------------------------------
PART1
SYS_P101
SQL> commit;
提交完成。
SQL> insert into interval_example values(to_date('2014-4-4','YYYY-MM-DD'),2);
已創建 1 行。
SQL> commit;
提交完成。
SQL> select t.partition_name from dba_tab_partitions t where t.table_owner=user and t.table_name=upper('interval_example');
PARTITION_NAME
------------------------------
PART1
SYS_P101
SYS_P102