Solved

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

Posted on 2004-09-22
5
1,133 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
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

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Background In several of the companies I have worked for, I noticed that corporate reporting is off loaded from the production database and done mainly on a clone database which needs to be kept up to date daily by various means, be it a logical…
Shell script to create broker configuration file using current broker Configuration, solely for purpose of backup on Linux. Script may need to be modified depending on OS-installation. Please deploy and verify the script in a test environment.
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.
This video shows how to Export data from an Oracle database using the Original Export Utility.  The corresponding Import utility, which works the same way is referenced, but not demonstrated.

726 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