在oracle 11g之前,如果我们往一个没有匹配到满足分区的RANGE分区写记录的时候会报 ORA-14400: inserted partition key does not
在Oracle 11g之前,如果我们往一个没有匹配到满足分区的RANGE分区写记录的时候会报 ORA-14400: inserted partition key does not map to any partition,,因为这个原因我已经半夜起来过好几次。
如果oracle在更新记录或者新增记录的时候发现没有匹配的分区能自动分区该多好,在oracle11g中oracle实现了这个功能。
看个简单的例子。
etl@DWTEST19> create table part_01
2 (
3 col01 date
4 )
5 partition by range(col01)
6 (
7 partition p201001 values less than ( to_date('20100201','yyyymmdd') ),
8 partition p201002 values less than ( to_date('20100301','yyyymmdd') )
9 )
10 /
Table created.
etl@DWTEST19> insert into part_01 values( to_date('20100301','yyyymmdd'));
insert into part_01 values( to_date('20100301','yyyymmdd'))
*
ERROR at line 1:
ORA-14400: inserted partition key does not map to any partition
可以看出在没有分区满足的时候会报错。
下面看看oracle11g提供的间隔分区功能
etl@DWTEST>create table part_01
2 (
3 col01 date
4 )
5 partition by range(col01)
6 interval (numtoyminterval(1,'MONTH'))
7 (
8 partition p201001 values less than ( to_date('20100201','yyyymmdd') )
9 )
10 /
Table created.
Elapsed: 00:00:00.08
etl@DWTEST>insert into part_01 values( to_date('20101001','yyyymmdd') );
1 row created.
Elapsed: 00:00:00.07
etl@DWTEST>select partition_name,high_value
2 from user_tab_partitions
3 where table_name='PART_01';
PARTITION_NAME HIGH_VALUE
--------------- --------------------------------------------------
P201001 TO_DATE(' 2010-02-01 00:00:00', 'SYYYY-MM-DD HH24:
MI:SS', 'NLS_CALENDAR=GREGORIAN')
SYS_P36675 TO_DATE(' 2010-11-01 00:00:00', 'SYYYY-MM-DD HH24:
MI:SS', 'NLS_CALENDAR=GREGORIAN')
Elapsed: 00:00:00.45
etl@DWTEST>insert into part_01 values( to_date('20100901','yyyymmdd') );
1 row created.
Elapsed: 00:00:01.37
etl@DWTEST>select partition_name,high_value
2 from user_tab_partitions
3 where table_name='PART_01';
PARTITION_NAME HIGH_VALUE
--------------- --------------------------------------------------
P201001 TO_DATE(' 2010-02-01 00:00:00', 'SYYYY-MM-DD HH24:
MI:SS', 'NLS_CALENDAR=GREGORIAN')
SYS_P36675 TO_DATE(' 2010-11-01 00:00:00', 'SYYYY-MM-DD HH24:
MI:SS', 'NLS_CALENDAR=GREGORIAN')
SYS_P36676 TO_DATE(' 2010-10-01 00:00:00', 'SYYYY-MM-DD HH24:
MI:SS', 'NLS_CALENDAR=GREGORIAN')
Elapsed: 00:00:00.43
可以看出Oracle很好的为我们处理了加分区的操作。
但是,分区名,分区名怎么指定呢?