Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 1144
  • Last Modified:

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.
0
Gaute Rønningen
Asked:
Gaute Rønningen
1 Solution
 
seazodiacCommented:
try this:

create or replace function set_date( no_of_days in number)
return DATE
as
return sysdate + no_of_days;
end;
/
0
 
Gaute RønningenAuthor Commented:
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 '+' ?
0
 
LeeMillerCommented:
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) ;
0
 
seazodiacCommented:
fix it : try this:


create or replace function set_date( no_of_days in number)
return DATE
as
test_date DATE;
begin
test_date := to_date(sysdate + no_of_days);
return test_date;
END;
/
0
 
CedDCommented:
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
0

Featured Post

What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now