Tuesday, April 03, 2007

Oracle 9i - How to add missing partitions

Assume, We need to insert missing partition as new partition with Oracle Range Partition.

Here is the simple example for that.

create table karth_test (a date,data char(10))
partition by range(a)
( partition p1 values less than (to_date('2007-01-01','YYYY-MM-DD')),
partition p2 values less than (to_date('2007-02-01','YYYY-MM-DD')),
partition p4 values less than (to_date('2007-04-01','YYYY-MM-DD'))
)

select partition_name pname, high_value from user_tab_partitions
where table_name ='KARTH_TEST' order by partition_name

alter table KARTH_TEST add partition p3 values less than (TO_DATE('2007-03-01','YYYY-MM-DD'))

-- Above statement raises ORA-14074: partition bound must collate higher than that of the last partition.

-- We can execute following statement to overcome above error

Alter table KARTH_TEST split partition p4 at (TO_DATE('2007-03-01','YYYY-MM-DD'))
into (partition p3, partition p4)

Drop table KARTH_TEST

No comments: