Home > Software engineering >  need to add start date and end date parameter in stored procedure (oracle)
need to add start date and end date parameter in stored procedure (oracle)

Time:12-17

I want to add start date and end date parameter in oracle to show the data between startdate and enddate ,Currently date is in this format 20221003,20221003,20221003 (yyyymmdd)

 to_date(posting_date,'yyyymmdd') >= to_date(TO_CHAR (:STARTDATE, 'yyyymmdd'),'yyyymmdd') and to_date(posting_date,'yyyymmdd') <= to_date(TO_CHAR (:ENDDATE, 'yyyymmdd'),'yyyymmdd')

CodePudding user response:

That's

create or replace procedure p_proc (par_start in number, par_end in number) is
begin
  select ...
  into ...
  from ...
  where posting_date between to_date(par_start, 'yyyymmdd') and to_date(par_end, 'yyyymmdd');
end;
/

presuming that posting_date columns' datatype is DATE (should be! If not, consider fixing data model; don't store dates in any other datatype column but DATE (or TIMESTAMP)).

If it is a number, then modify it to

where to_date(posting_date, 'yyyymmdd') between <the rest is just the same as above>
  • Related