Home » SQL & PL/SQL » SQL & PL/SQL » truncate partition (oracle 11.2.0.3 sun solaris 10.5)
truncate partition [message #598110] Thu, 10 October 2013 09:10 Go to next message
guddu_12
Messages: 227
Registered: April 2012
Location: UK
Senior Member
Dear all,

I am trying to truncate a partition using syntax .
ALTER TABLE SALES6 TRUNCATE PARTITION FOR(DATE '02-03-07')

but when i query back to table i can still see the data it is not truncating.

create table sales6
(
   sales_id    number,
   sales_dt    date
)
partition by range (sales_dt)
(
   partition p0701 values less than (to_date('2007-02-01','yyyy-mm-dd')),
   partition p0702 values less than (to_date('2007-03-01','yyyy-mm-dd')),
   partition p0703 values less than (to_date('2007-04-01','yyyy-mm-dd')),
   partition p0704 values less than (to_date('2007-05-01','yyyy-mm-dd')),
   partition p0705 values less than (to_date('2007-07-01','yyyy-mm-dd'))   
);

INSERT INTO sales6 VALUES( 1, TO_DATE('02-06-2007','DD-MM-YYYY'));
INSERT INTO sales6 VALUES( 1, TO_DATE('12-02-2007','DD-MM-YYYY'))
INSERT INTO sales6 VALUES( 1, TO_DATE('11-01-2007','DD-MM-YYYY'))
INSERT INTO sales6 VALUES( 1, TO_DATE('15-05-2007','DD-MM-YYYY'))
INSERT INTO sales6 VALUES( 1, TO_DATE('27-04-2007','DD-MM-YYYY'))

ALTER TABLE SALES6 TRUNCATE PARTITION FOR(DATE '02-03-07')


what's wrong here
Re: truncate partition [message #598111 is a reply to message #598110] Thu, 10 October 2013 09:13 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>what's wrong here
Problem Exists Between Keyboard And Chair.

what terminates SQL statements?
Re: truncate partition [message #598112 is a reply to message #598110] Thu, 10 October 2013 09:17 Go to previous messageGo to next message
flyboy
Messages: 1903
Registered: November 2006
Senior Member
Maybe, when using some Oracle features (as DATE literals), you should firstly read the documentation about it.
http://docs.oracle.com/cd/E11882_01/server.112/e41084/sql_elements003.htm#BABGIGCJ
Then, you would realize that you are truncating partition for March 7th, 0002.

What about using TO_DATE expression, the same as in CREATE TABLE and INSERT statements?
Re: truncate partition [message #598113 is a reply to message #598111] Thu, 10 October 2013 09:18 Go to previous messageGo to next message
guddu_12
Messages: 227
Registered: April 2012
Location: UK
Senior Member
ok i understand semicolon is missing in the insert statement, but i have loaded the data and commited it but still the truncate command is not able to truncate the data for that particular partition
Re: truncate partition [message #598114 is a reply to message #598113] Thu, 10 October 2013 09:19 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
>the data for that particular partition
which partition is that?
Re: truncate partition [message #598115 is a reply to message #598113] Thu, 10 October 2013 09:19 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
read flyboys post
Re: truncate partition [message #598116 is a reply to message #598115] Thu, 10 October 2013 09:22 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
In fact the issue is the same one me and Michel pointed out at the end of your other post.
Re: truncate partition [message #598118 is a reply to message #598116] Thu, 10 October 2013 09:30 Go to previous messageGo to next message
guddu_12
Messages: 227
Registered: April 2012
Location: UK
Senior Member
I couldn't understand, i want to truncate the partition p0703 . my above query should truncate the p0703. If it is problem with literal then in what format it will accept the value in current sceniro. as the table is already built and data is loaded. I am sorry if i sould foolish
Re: truncate partition [message #598119 is a reply to message #598118] Thu, 10 October 2013 09:33 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
guddu_12 wrote on Thu, 10 October 2013 07:30
I couldn't understand, i want to truncate the partition p0703


where is the "P" as part of the partition name below?

>ALTER TABLE SALES6 TRUNCATE PARTITION FOR(DATE '02-03-07')
Re: truncate partition [message #598121 is a reply to message #598118] Thu, 10 October 2013 09:38 Go to previous messageGo to next message
cookiemonster
Messages: 13920
Registered: September 2008
Location: Rainy Manchester
Senior Member
guddu_12 wrote on Thu, 10 October 2013 15:30
If it is problem with literal then in what format it will accept the value in current sceniro.

Do you really think the answer to that question isn't in the documentation page flyboy linked to?
read it.
Re: truncate partition [message #598125 is a reply to message #598121] Thu, 10 October 2013 09:44 Go to previous messageGo to next message
guddu_12
Messages: 227
Registered: April 2012
Location: UK
Senior Member
Answer to the Blackswan, there is another method to truncate the partition by partition name but the one i have mention above i came to know the it will truncate the partition based on the values.
THis is the other way of doing it but it will not help me.

ALTER TABLE SALES6 TRUNCATE PARTITION (P0702)
Re: truncate partition [message #598128 is a reply to message #598125] Thu, 10 October 2013 09:49 Go to previous messageGo to next message
guddu_12
Messages: 227
Registered: April 2012
Location: UK
Senior Member
Thnaks,

Flyboy links helped me
Re: truncate partition [message #598130 is a reply to message #598128] Thu, 10 October 2013 09:51 Go to previous message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
  1* select DATE '02-03-07' from dual
SQL> /

DATE'02-0
---------
07-MAR-02

Previous Topic: date conversion format issue
Next Topic: Package related Query
Goto Forum:
  


Current Time: Thu Apr 25 05:01:26 CDT 2024