recent

Titulo

Dropping a Default Partition of an Interval Partitioned Table

This article talks and demonstrate the step-by-step instructions on how to drop a default partition from Oracle Interval partitioned table? Any partitions of a table but default partition can be dropped without much pain. Oracle will throw ORA-14758 when you try to drop the default partition on interval partition table.
What is ORA-14758? ORA-14758: Last partition in the range section cannot be dropped This error occurs, when you try to drop the last statically created partition (from the initial table creation DDL) from a Interval Partitioned table. The easiest workaround to drop the last statically created partition is to temporarily disable the interval partition (which switches to range partition), drop the last statically created partition and switch it back to interval partition. Lets do what we just talked about.

 CREATE TABLE invoices 
  ( 
     invoice_no   NUMBER NOT NULL, 
     invoice_date DATE NOT NULL, 
     comments     VARCHAR2(500) 
  ) partition BY RANGE ( invoice_date ) interval ( numtoyminterval(1, 'month') ) 
( PARTITION p_first VALUES less than (to_date('01-jan-2012', 'DD-MON-YYYY')), 
PARTITION p_second VALUES less than (to_date('01-feb-2012', 'DD-MON-YYYY')) ); 

Output: table INVOICES created.

--select table partitions
SELECT table_owner, 
       table_name, 
       partition_name 
FROM   dba_tab_partitions 
WHERE  table_name LIKE 'INVOICES'; 

TABLE_OWNER                    TABLE_NAME                     PARTITION_NAME            
------------------------------ ------------------------------ ------------------------------
PRABINBANIYA                   INVOICES                       P_FIRST                      
PRABINBANIYA                   INVOICES                       P_SECOND                    



--Drop partition
ALTER TABLE prabinbaniya.invoices DROP PARTITION p_second;
Error starting at line 28 in command:
alter table prabinbaniya.invoices drop partition p_second
Error report:
SQL Error: ORA-14758: Last partition in the range section cannot be dropped


--reset range partition table
alter table prabinbaniya.invoices set interval ();
table PRABINBANIYA.INVOICES altered.

--dropping a default partition
ALTER TABLE invoices DROP PARTITION p_second;
table INVOICES altered.

--Change the interval to what it was before
alter table invoices set interval (numtoyminterval(1,'month'))
table INVOICES altered.

SELECT table_owner, 
       table_name, 
       partition_name 
FROM   dba_tab_partitions 
WHERE  table_name LIKE 'INVOICES'; 

TABLE_OWNER                    TABLE_NAME                     PARTITION_NAME            
------------------------------ ------------------------------ ------------------------------
PRABINBANIYA                   INVOICES                       P_FIRST


Bingo! the partition is now dropped. There are few other ways and I find this approach easy. If you see any issue with this feel free to comment below.


Interested in working with me? I can be reached at pbaniya04[at]gmail.com for any questions, consulting opportunities or you may drop a line to say HELLO. Thank your again for visiting my blog and looking forward to serving you more.

Have a Database-ious Day!

1 comment

  1. But the issue is after few partitions again this issue will occurs and need to follow this steps. Any permanent way to solve this

    ReplyDelete

Powered by Blogger.