There is a query in Oracle

select krt_log from t_trm_log, (select to_date('YYYYMMDD')a from dual) dl where tm>decode(dl.a, to_date('20150203', 'YYYYMMDD'), trunc(sysdate, 'DD'), dl.a) order by id desc 

This request is used to generate a report, it is required to modify it in order not to enter the date in the format 20150203 , but to write the number of days, for example, 10 days and so that a larger number of days would not be available. Who prompts, thanks in advance.

  • What is tm ? and 10 days from what? from the current time? - Anton Komyshan
  • First, the subquery is completely unnecessary, the one in which the to_date parameter is missing. And the number of days until a date is obtained simply by subtracting the dates. those. Something like sysdate - tm (assuming that tm data type is date) - Mike

1 answer 1

If tm is a column of the t_trm_log table, then writing a query like this will always display a report for the last 10 days.

 select krt_log from t_trm_log t where t.tm between trunc(sysdate - 10) and trunc(sysdate)