Link to home
Start Free TrialLog in
Avatar of Gaute Rønningen
Gaute RønningenFlag for Norway

asked on

Need help with a PL/SQL function: X days from today

I need a function which one should be able to enter an amount of days as parameter(X) , and the function should be able to return the date which is X days ahead of SYSDATE.

Any help appreciated,
eX.
Avatar of seazodiac
seazodiac
Flag of United States of America image

try this:

create or replace function set_date( no_of_days in number)
return DATE
as
return sysdate + no_of_days;
end;
/
Avatar of Gaute Rønningen

ASKER

Errors for FUNCTION SET_DATE:

LINE/COL ERROR
-------- -----------------------------------------------------------------
4/16     PLS-00103: Encountered the symbol "+" when expecting one of the
         following:
         := . ( @ % ; not null range default character

So I'm guessing some other sign for '+' ?
Avatar of LeeMiller
LeeMiller

Maybe this:

CREATE OR REPLACE
FUNCTION add_to_date
  ( days IN NUMBER)
  RETURN  DATE IS
     
   new_date DATE;

BEGIN
    new_date :=  SYSDATE+days;
    RETURN new_date ;
EXCEPTION
   WHEN others THEN
       dbms_output.put_line(sqlerrm) ;
ASKER CERTIFIED SOLUTION
Avatar of seazodiac
seazodiac
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
Try this :

create or replace function set_date( no_of_days in number)
return DATE
as
begin
declare dateret date;
begin

select sysdate+no_of_days
into dateret
from dual;


return dateret;
end;
end;
/


select set_date(12) from dual;

SET_DATE(12)
------------------
04/10/2004 17:07:23