Home » SQL & PL/SQL » SQL & PL/SQL » Oracle Intervel partition. (11.1.0.6.0)
Oracle Intervel partition. [message #544860] Fri, 24 February 2012 05:38 Go to next message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

Hi ALL,

i have want to drop the partion based on more then 60 days old.
history tables should be dropped by partitions instead of deleting records from the tables.

How can we compare with date older than 60 days in table with table partition.

 CREATE TABLE SOLN_ITEM_HIST
(
  ORDERNUMBER    VARCHAR2(50 BYTE) NOT NULL,
  M_ID           NUMBER  NOT NdULL,
  MODIFIED_ON    DATE   NOT NULL,
  MODIFIED_BY    VARCHAR2(100 BYTE) NOT NULL
)
PARTITION BY RANGE (MODIFIED_ON) 
( PARTITION P1_ORDER_ITEM_DATA VALUES LESS THAN 
      (TO_DATE(' 2011-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
  PARTITION VALUES LESS THAN 
  (TO_DATE(' 2012-02-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) )


Thanks
Re: Oracle Intervel partition. [message #544869 is a reply to message #544860] Fri, 24 February 2012 06:15 Go to previous messageGo to next message
Michel Cadot
Messages: 68773
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Quote:
How can we compare with date older than 60 days in table with table partition.


In the same way than with a table without partition: "where modified_on < sysdate-60".

Regards
Michel
Re: Oracle Intervel partition. [message #544874 is a reply to message #544869] Fri, 24 February 2012 06:21 Go to previous messageGo to next message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

Table having partition...i need to drop the partition based on "where modified_on < sysdate-60",in case how can compare with table data with partition..
It' monthly partition...How can achive this... I dnot' want use delete operation...
Re: Oracle Intervel partition. [message #544875 is a reply to message #544874] Fri, 24 February 2012 06:23 Go to previous messageGo to next message
Michel Cadot
Messages: 68773
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Compare with dba_tab_partitions.high_value.

Regards
Michel
Re: Oracle Intervel partition. [message #544879 is a reply to message #544875] Fri, 24 February 2012 07:06 Go to previous messageGo to next message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

Thanks Micheal got it..
Re: Oracle Intervel partition. [message #544897 is a reply to message #544879] Fri, 24 February 2012 09:35 Go to previous messageGo to next message
S.Rajaram
Messages: 1027
Registered: October 2006
Location: United Kingdom
Senior Member
Alternatively you can use the extended partition syntax. It gives you a lot of flexibility.

Check this link for more information about extended partition syntax.

http://oraexplorer.com/2008/12/new-extended-partition-syntax-in-11g/

Regards

Raj

Re: Oracle Intervel partition. [message #544908 is a reply to message #544897] Fri, 24 February 2012 10:24 Go to previous messageGo to next message
Michel Cadot
Messages: 68773
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
Yes, forgot it, nice to remind it.

Regards
Michel
Re: Oracle Intervel partition. [message #544932 is a reply to message #544908] Sat, 25 February 2012 02:40 Go to previous messageGo to next message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

Thanks You all..
Re: Oracle Intervel partition. [message #545047 is a reply to message #544932] Mon, 27 February 2012 00:35 Go to previous messageGo to next message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

Sorry...
i am not able to extract the dba_tab_partitions.high_value,because it is long column.
How to extract the data only?
Re: Oracle Intervel partition. [message #545048 is a reply to message #545047] Mon, 27 February 2012 00:36 Go to previous messageGo to next message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

How to extract the high_value from date only?
Re: Oracle Intervel partition. [message #545055 is a reply to message #545048] Mon, 27 February 2012 01:23 Go to previous messageGo to next message
Michel Cadot
Messages: 68773
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
You have to use a procedure that fetches the high value and returns it as a varchar2.
Raj suggested you a nice solution, did you investigate it?

Regards
Michel
Re: Oracle Intervel partition. [message #545275 is a reply to message #545055] Tue, 28 February 2012 04:01 Go to previous messageGo to next message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

Tried like, not working. Please suggest me,Below alter is this right?

alter table SOLN_ITEM_HIST drop partition for(to_date('01/01/2012','mm/dd/yyyy'));

Getting error :ORA-02149: Specified partition does not exist
But partition name exist in table...

 PARTITION_NAME  HIGH_VALUE
SYS_P48163       TO_DATE(' 2012-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')
Re: Oracle Intervel partition. [message #545281 is a reply to message #545275] Tue, 28 February 2012 04:23 Go to previous messageGo to next message
Michel Cadot
Messages: 68773
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
But the limit value is excluded from the partition (if it is a range partitioning), so Oracle is right.

Regards
Michel
Re: Oracle Intervel partition. [message #545284 is a reply to message #545281] Tue, 28 February 2012 04:28 Go to previous messageGo to next message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

i didn't get you what are you trying to say...
Right now table contains 5 partitions...above partition is 2 one...
How to drop tell me?
Re: Oracle Intervel partition. [message #545285 is a reply to message #545284] Tue, 28 February 2012 04:30 Go to previous messageGo to next message
cookiemonster
Messages: 13975
Registered: September 2008
Location: Rainy Manchester
Senior Member
If you read the Raj's link carefully you'll see that value used in the drop partition command isn't the high value.
It's a value that would be contained in the partition.
Re: Oracle Intervel partition. [message #545288 is a reply to message #545285] Tue, 28 February 2012 04:34 Go to previous messageGo to next message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

verified Link,there is merging partition then dropping.. Please help me how to do..
Re: Oracle Intervel partition. [message #545290 is a reply to message #545288] Tue, 28 February 2012 04:38 Go to previous messageGo to next message
cookiemonster
Messages: 13975
Registered: September 2008
Location: Rainy Manchester
Senior Member
Read the second sentance in my last post.
Re: Oracle Intervel partition. [message #545292 is a reply to message #545284] Tue, 28 February 2012 04:41 Go to previous messageGo to next message
Michel Cadot
Messages: 68773
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
muralikri wrote on Tue, 28 February 2012 11:28
i didn't get you what are you trying to say...
Right now table contains 5 partitions...above partition is 2 one...
How to drop tell me?


What I said is that the limit of a partition is NOT in the partition:
SQL> create table t (val integer) partition by range (val) 
  2  (partition p1 values less than (100),
  3  partition p2 values less than (maxvalue));

Table created.

SQL> insert into t values (100);

1 row created.

SQL> select * from t partition(p1);

no rows selected

SQL> select * from t partition(p2);
       VAL
----------
       100

1 row selected.

Regards
Michel
Re: Oracle Intervel partition. [message #545295 is a reply to message #545292] Tue, 28 February 2012 04:50 Go to previous messageGo to next message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

My table structure like,table is interval partition by monthly......
Every month it's creating new partition,how to drop the partition every moth,suggest by Raj's link.

CREATE TABLE SOLN_ITEM_HIST
(
  ORDERNUMBER    VARCHAR2(50 BYTE) NOT NULL,
  M_ID           NUMBER  NOT NdULL,
  MODIFIED_ON    DATE   NOT NULL,
  MODIFIED_BY    VARCHAR2(100 BYTE) NOT NULL
)
PARTITION BY RANGE (MODIFIED_ON)
INTERVAL(NUMTOYMINTERVAL(1, 'MONTH'))
(PARTITION P1_ORD_HIST VALUES LESS THAN (TO_DATE(' 1900-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))
 PARTITION VALUES LESS THAN (TO_DATE(' 2012-01-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN'))),  
 PARTITION VALUES LESS THAN (TO_DATE(' 2012-03-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')),
 PARTITION VALUES LESS THAN (TO_DATE(' 2012-07-01 00:00:00', 'SYYYY-MM-DD HH24:MI:SS', 'NLS_CALENDAR=GREGORIAN')) )
Re: Oracle Intervel partition. [message #545296 is a reply to message #545295] Tue, 28 February 2012 04:52 Go to previous messageGo to next message
cookiemonster
Messages: 13975
Registered: September 2008
Location: Rainy Manchester
Senior Member
Use a value that's contained in the partition. Not the high value because that isn't contained in the partition.
How many different ways do we need to say this very simple thing?
Re: Oracle Intervel partition. [message #545298 is a reply to message #545296] Tue, 28 February 2012 04:54 Go to previous messageGo to next message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

Can you help me please post the sql's
Re: Oracle Intervel partition. [message #545299 is a reply to message #545298] Tue, 28 February 2012 04:56 Go to previous messageGo to next message
cookiemonster
Messages: 13975
Registered: September 2008
Location: Rainy Manchester
Senior Member
YOu've already got the sql. You just need to supply the correct date. Any date contained in the partition will do. You have lots to pick from. just try it!
Re: Oracle Intervel partition. [message #545300 is a reply to message #545299] Tue, 28 February 2012 04:58 Go to previous messageGo to next message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

Tried not working... raising error : ORA-02149: Specified partition does not exist
alter table SOLN_ITEM_HIST drop partition for(to_date('01/01/2012','mm/dd/yyyy'));
Re: Oracle Intervel partition. [message #545301 is a reply to message #545299] Tue, 28 February 2012 04:59 Go to previous messageGo to next message
Michel Cadot
Messages: 68773
Registered: March 2007
Location: Saint-Maur, France, https...
Senior Member
Account Moderator
So use "to_date('01/01/2012','mm/dd/yyyy')-1/86400" for instance.

Regards
Michel

Re: Oracle Intervel partition. [message #545309 is a reply to message #545301] Tue, 28 February 2012 05:27 Go to previous message
muralikri
Messages: 638
Registered: August 2011
Location: chennai
Senior Member

@Micheal
Awesome!!!! Thanks a lot
Previous Topic: Horizontal Fragmentation in Oracle 10g Express edition
Next Topic: Database tables column to row
Goto Forum:
  


Current Time: Wed Dec 24 18:35:01 CST 2025