Solved

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

Posted on 2004-09-22
5
1,128 Views
Last Modified: 2012-08-13
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
Comment
Question by:Gaute Rønningen
5 Comments
 
LVL 23

Expert Comment

by:seazodiac
ID: 12123547
try this:

create or replace function set_date( no_of_days in number)
return DATE
as
return sysdate + no_of_days;
end;
/
0
 

Author Comment

by:Gaute Rønningen
ID: 12123594
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
 
LVL 2

Expert Comment

by:LeeMiller
ID: 12123703
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
 
LVL 23

Accepted Solution

by:
seazodiac earned 250 total points
ID: 12123717
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
 

Expert Comment

by:CedD
ID: 12123755
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

PRTG Network Monitor: Intuitive Network Monitoring

Network Monitoring is essential to ensure that computer systems and network devices are running. Use PRTG to monitor LANs, servers, websites, applications and devices, bandwidth, virtual environments, remote systems, IoT, and many more. PRTG is easy to set up & use.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

This article started out as an Experts-Exchange question, which then grew into a quick tip to go along with an IOUG presentation for the Collaborate confernce and then later grew again into a full blown article with expanded functionality and legacy…
Note: this article covers simple compression. Oracle introduced in version 11g release 2 a new feature called Advanced Compression which is not covered here. General principle of Oracle compression Oracle compression is a way of reducing the d…
Via a live example, show how to take different types of Oracle backups using RMAN.
This video shows how to Export data from an Oracle database using the Datapump Export Utility.  The corresponding Datapump Import utility is also discussed and demonstrated.

785 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question