Skip to Main Content
  • Questions
  • Partitioning for Existing tables in 12c

Breadcrumb

Question and Answer

Connor McDonald

Thanks for the question, Mohd..

Asked: November 15, 2016 - 6:26 pm UTC

Last updated: November 17, 2016 - 2:36 am UTC

Version: 12c

Viewed 10K+ times! This question is

You Asked

Dear Experts,

Thanks a lot for your advise and support to the needy.

I am in process of partitioning on DATE INTERVAL on existing table which holding the data.

1. Application team wants to partition for future data and no need to partition the old data which is there in the table until today, Is it possible without recreating/dropping the existing table.......I mean just add partition tomorrow onwards?

2. I went through
https://asktom.oracle.com/pls/asktom/f?p=100:11:0::::P11_QUESTION_ID:869096700346654484

If point 1 is not possible then what is the best way to achieve it in 12c ? is it dbms_redefinition is the only ways as explained in your answer (link) or we have other better method to do partition for existing tables?

Regards
Shah Nawaz

and Connor said...

If the current table is just to be the earliest partition (and you dont want to split the existing data), a simple exchange will suffice.

SQL> create table t as
  2  select owner, object_name, created
  3  from dba_objects
  4  where created is not null;

Table created.

SQL>
SQL>
SQL> create table t_par
  2  ( owner varchar2(128),
  3    object_name varchar2(128),
  4    created date )
  5  partition by range ( created )
  6  (
  7    partition p1 values less than ( date '2016-11-20' )
  8  );

Table created.

SQL>
SQL> alter table t_par exchange partition p1 with table t;

Table altered.


Rating

  (1 rating)

Is this answer out of date? If it is, please let us know via a Comment

Comments

Exchange partition ?!?!?!?!

Rajeshwaran, Jeyabal, November 16, 2016 - 12:27 pm UTC

....
Is it possible without recreating/dropping the existing table.......I mean just add partition tomorrow onwards?
....


The goal here is to converted a non-partitioned table to a partitioned one, without dropping or recreating it.

dbms_redefinition is purely online process, but that is ruled out.

Based on the response provided, How would that convert 'T' into a partitioned Table. ?

demo@ORA12C> select partitioned from user_tables
  2  where table_name ='T';

PAR
---
NO

1 row selected.


One way would be switch into 12cR2 and convert non-partitioned table to partitioned one using ALTER statements.

http://docs.oracle.com/database/122/VLDBG/evolve-nopartition-table.htm#VLDBG-GUID-5FDB7D59-DD05-40E4-8AB4-AF82EA0D0FE5

Any options in 12cR1 ?
Connor McDonald
November 17, 2016 - 2:36 am UTC

For the original poster, this achieves the requirement (ie, existing data becomes one historical partition).

I could have added the final step:

rename t_par to t;

but I thought that was fairly self-evident.

More to Explore

VLDB

If you are new to partitioning, check out Connor McDonald's introduction series here.

VLDB

Documentation set on VLDB and Partitioning.