Skip to content
Advertisement

How do I find data from this day exactly one year ago in oracle?

Merry Christmas,

I am using the below query to get the prices, but my requirement is to get the data for last one year from trunc(sysdate). i have tried using DATEADD function but its gives me an error

cast(p.asof as DATE) = cast(DATEADD(Year, -1, GETDATE()) as DATE)

select idvalue, p.asof as DATE_, p.instrument, p.price
from instruments i
inner join prices_equity_closing p on p.instrument = i.pkey
inner join instruments_ids id on i.ids = id.idset
where
id.idvalue in ('MRVE3.SA')
and id.idtype in ('RIC')
and p.asof = trunc(sysdate)-1
order by i.exchange, i.type, p.asof desc;

Can anyone please help, what all changes i require to get the desired result ?

Advertisement

Answer

use add_months and sysdate:

select add_months(sysdate,-12) x from dual
User contributions licensed under: CC BY-SA
5 People found this is helpful
Advertisement