Link to home
Start Free TrialLog in
Avatar of gram77
gram77Flag for India

asked on

sql to delete rows from a table that are more than 3 days old.

I have a table with col1 - varchar2 and col2 - date columns
I want to remove those rows that are more 3 days old.
I don't want to use pl/sql code, I want to do it using sql
I tried using this statement but it failed:

delete from abc where to_date(dt) = to_date(sysdate)-3 ;

shows 0 rows deleted.
ASKER CERTIFIED SOLUTION
Avatar of Jinesh Kamdar
Jinesh Kamdar
Flag of India image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Avatar of pollock_d
pollock_d

you can try something like...
delete from abc where datepart(day, dt) > 3

Open in new window

Do u ur dates have a time component to it? E.g. 2-FEB-2008 11:33:54 or just 2-FEB-2008 00:00:00
try this
delete from abc where dt < sysdate -3;

assuming dt is a date field.
it should work
try this
delete from abc where dt < sysdate -3;

assuming dt is a date field.
it should work
@ysd - Request u to kindly check the previous posts before repeating similar solutions.
Avatar of gram77

ASKER

DT      
---------
06-FEB-08
07-FEB-08
08-FEB-08
08-FEB-08
08-FEB-08
08-FEB-08

delete from abc where dt < sysdate -3;

sysdate should be 08-FEB-08

0 rows deleted
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Avatar of awking00
awking00
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
My bad :)  Get to leafing through these quickly and don't read the whole thing.  Thanks awking00!