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.
gram77Asked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jinesh KamdarCommented:
delete from abc where dt < sysdate - 3 ;
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
pollock_dCommented:
you can try something like...
delete from abc where datepart(day, dt) > 3

Open in new window

0
Jinesh KamdarCommented:
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
0
Big Business Goals? Which KPIs Will Help You

The most successful MSPs rely on metrics – known as key performance indicators (KPIs) – for making informed decisions that help their businesses thrive, rather than just survive. This eBook provides an overview of the most important KPIs used by top MSPs.

ysdCommented:
try this
delete from abc where dt < sysdate -3;

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

assuming dt is a date field.
it should work
0
Jinesh KamdarCommented:
@ysd - Request u to kindly check the previous posts before repeating similar solutions.
0
gram77Author Commented:
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
0
Jinesh KamdarCommented:
0 Rows Deleted is the correct o/p since none of ur rows are older than 3 days.
Isn't that what u wanted ?
0
jwittenmCommented:
you need to 'trunc' the date field.  i.e., where trunc(dt) = trunc(sysdate - 3)
0
awking00Information Technology SpecialistCommented:
I think the use of trunc is the most accurate way to go, but jwittenm's proposal needs to include the "less than" operator as well -
... where trunc(dt) <= trunc(sysdate - 3)
0
jwittenmCommented:
My bad :)  Get to leafing through these quickly and don't read the whole thing.  Thanks awking00!
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Oracle Database

From novice to tech pro — start learning today.