参考资料:http://blog.chinaunix.net/uid-21943216-id-4062400.html

一、建按月自增分区表:
1.1建表
SQL> create table month_interval_partition_table (id number,time_col date) partition by range(time_col)
  2  interval (numtoyminterval(1,'month'))
  3  (
  4   partition p_month_1 values less than (to_date('2014-01-01','yyyy-mm-dd'))
  5  );
 
Table created
1.2 查看现在分区
SQL> select table_name,partition_name from user_tab_partitions where table_name='MONTH_INTERVAL_PARTITION_TABLE';

1.3、插入数据
SQL> begin
  2  for i in 0..11 loop
  3   insert into MONTH_INTERVAL_PARTITION_TABLE values(i,add_months(to_date('2014-01-01','yyyy-mm-dd'),i));
  4  end loop;
  5  commit;
  6  end;
  7  /
 
PL/SQL procedure successfully completed

SQL> select table_name,partition_name from user_tab_partitions where table_name='MONTH_INTERVAL_PARTITION_TABLE';

神通kstore数据库查看分区表

select * From V_SYS_TAB_PARTITIONS   

1.5查看其中一个分区数据


SQL> select * From MONTH_INTERVAL_PARTITION_TABLE partition(SYS_P22);

二、创建按天的分区表


2.1建表
SQL> create table day_interval_partition_table (id number,time_col date) partition by range(time_col)
  2  interval (numtodsinterval(1,'day'))
  3  (
  4   partition p_day_1 values less than (to_date('2014-01-01','yyyy-mm-dd'))
  5  );
 
Table created
 
2.2、查看现在分区
SQL> select table_name,partition_name from user_tab_partitions where table_name='DAY_INTERVAL_PARTITION_TABLE';
 
TABLE_NAME                     PARTITION_NAME
------------------------------ ------------------------------
DAY_INTERVAL_PARTITION_TABLE   P_DAY_1


2.3、插入数据
SQL> begin
  2  for i in 1..12 loop
  3   insert into DAY_INTERVAL_PARTITION_TABLE values(i,trunc(to_date('2014-01-01','yyyy-mm-dd')+i));
  4  end loop;
  5  commit;
  6  end;
  7  /
 
PL/SQL procedure successfully completed


2.4查看分区
SQL> select table_name,partition_name from user_tab_partitions where table_name='DAY_INTERVAL_PARTITION_TABLE';

2.5查看数据
SQL> select table_name,partition_name from user_tab_partitions where table_name='DAY_INTERVAL_PARTITION_TABLE';

查看某个分区数据

select * From DAY_INTERVAL_PARTITION_TABLE partition(SYS_P39);