to_date expects to receive a char, if your field is of type Number, then you need to parse number to char first.
select * from carros car where to_date(to_char(to_date(to_char(car.datacompra),'yyyymmdd'),'dd-mm-yyyy')) = trunc(sysdate - 7)
Source : TO_DATE documentation
Issue 1
My first correction proposal was not adequate, I think this query will better meet your needs:
select * from carros car where to_date(LPAD(to_char(car.datacompra), 8,'0'),'yyyymmdd')= trunc(sysdate - 7)
I removed some transformations, and added the LPAD, to ensure that the to_date will work, preventing the error from occurring.
Documentation LPAD
What kind of field
datacompra
?– David
is number... yyyymmdd but is number
– novato
I tested it here and it worked.. how big the field is ?
– David
the size of the field is
number(8,0)
– novato