我们所有的Oracle 10g表都有一个名为DATE类型的业务日期的主键。 表已经分区到2014年1月31日。使用上面的业务日期列,我需要在2014年的剩余11个月进行分区, 你能告诉我应该采取下面列出的方法吗?
1
ALTER TABLE NRGPC.MY_TABLE SPLIT PARTITION MY_TABLE_DEFAULT AT (TO_DATE('02/01/2014', 'MM/DD/YYYY'))
INTO (PARTITION MY_TABLE_PRT0214 TABLESPACE NRGPC_DATA, PARTITION MY_TABLE_DEFAULT ) UPDATE INDEXES;
ANALYZE TABLE NRGPC.MY_TABLE PARTITION (MY_TABLE_PRT0214 ) COMPUTE STATISTICS;
ALTER TABLE NRGPC.MY_TABLE SPLIT PARTITION MY_TABLE_DEFAULT AT (TO_DATE('03/01/2014', 'MM/DD/YYYY'))
INTO (PARTITION MY_TABLE_PRT0314 TABLESPACE NRGPC_DATA, PARTITION MY_TABLE_DEFAULT ) UPDATE INDEXES;
ANALYZE TABLE NRGPC.MY_TABLE PARTITION (MY_TABLE_PRT0314) COMPUTE STATISTICS;
。 。 。 同样......
OR
2
PCTUSED 40 PCTFREE 20
PARTITION BY RANGE (BUSINESS_DT)
(
PARTITION MY_TABLE_2014_02 VALUES LESS THAN (TO_DATE(' 2014-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
TABLESPACE NRGPC_DATA
PCTFREE 0,
PARTITION MY_TABLE_2014_03 VALUES LESS THAN (TO_DATE(' 2014-04-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
TABLESPACE NRGPC_DATA
PCTFREE 0,
。 。 。 同样......
感谢您的帮助。
答案 0 :(得分:2)
如果您已经有默认分区,则需要将其拆分到理想的位置:
SQL> create table t (x date primary key)
2 partition by range(x) (
3 partition p_201312 values less than (to_date('20140101','YYYYMMDD')),
4 partition p_default values less than (maxvalue)
5 )
6 /
SQL> alter table t split partition p_default at(to_date('20140201','YYYYMMDD'))
2 into (partition p_201401, partition p_default)
3 /
SQL> select partition_name, high_value from user_tab_partitions
2 where table_name = 'T';
PARTITION_NAME
--------------------------------------------------------------------------------
HIGH_VALUE
--------------------------------------------------------------------------------
P_201312
TO_DATE(' 2014-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
P_201401
TO_DATE(' 2014-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIA
P_DEFAULT
MAXVALUE
当要描述分区方法和初始分区集时,在CREATE TABLE语句中使用第二个语句。请注意,如果您的默认分区不为空,则可能需要在拆分后重新创建索引(或使用UPDATE INDEXES选项)。
此外,如果要在范围的模块中添加分区(在最小值和最大值之间),则需要拆分最接近分割点的分区而不是默认分区:
SQL> create table t (x int, y int)
2 partition by range (y) (
3 partition p_0 values less than(1),
4 partition p_1 values less than(2),
5 partition p_2 values less than(3),
6 partition p_3 values less than(4),
7 partition p_d values less than(maxvalue)
8 )
9 /
SQL> alter table t drop partition p_2
2 /
SQL> alter table t split partition p_d at(3)
2 into (partition p_2, partition p_d)
3 /
alter table t split partition p_d at(3)
*
error in line 1:
ORA-14080: Partition cannot be split along the specified high bound
SQL> select partition_name, high_value
2 from user_tab_partitions where table_name = 'T';
PARTITION_NAME
--------------------------------------------------------------------------------
HIGH_VALUE
--------------------------------------------------------------------------------
P_0
1
P_1
2
P_3
4
P_D
MAXVALUE
SQL> alter table t split partition p_3 at(3)
2 into (partition p_2, partition p_3)
3 /
SQL> select partition_name, high_value
2 from user_tab_partitions where table_name = 'T';
PARTITION_NAME
--------------------------------------------------------------------------------
HIGH_VALUE
--------------------------------------------------------------------------------
P_D
MAXVALUE
P_3
4
P_2
3
P_1
2
P_0
1