Smart questions
Smart answers
Smart people
INTELLIGENT WORK FORUMS
FOR COMPUTER PROFESSIONALS

Member Login

Come Join Us!

Are you a
Computer / IT professional?
Join Tek-Tips now!
  • Talk With Other Members
  • Be Notified Of Responses
    To Your Posts
  • Keyword Search
  • One-Click Access To Your
    Favorite Forums
  • Automated Signatures
    On Your Posts
  • Best Of All, It's Free!

Join Tek-Tips
*Tek-Tips's functionality depends on members receiving e-mail. By joining you are opting in to receive e-mail.

LINK TO THIS FORUM!

Add Stickiness To Your Site By Linking To This Professionally Managed Technical Forum.
Just copy and paste the
code below into your site.

Partner With Us!

"Best Of Breed" Forums Add Stickiness To Your Site
Partner Button
(Download This Button Today!)

Feedback

"...The enviroment is simple, natural and efficient. The members are competent, educated and professionals..."

Geography

Where in the world do Tek-Tips members come from?
slicendice (Programmer)
7 Nov 11 7:26
Hi
I have two variables that are involved in processing some appointment data - one is the start time of the appointment and the other is the duration (in minutes). I need to calculate the end time of the appointment using those two items - which in itself is not a complex concept! I know I can add a number of minutes to a time in SQL using something like:

CODE

    SELECT to_char(to_date(10.40, 'HH24.MI') + INTERVAL '30' MINUTE, 'HH24:MI')
    FROM dual;

This works OK in that it gives me 11.10 as the result. However, if I try and build this in PL/SQL I get problems. If I try something like this:

CODE

DECLARE
    start_time  VARCHAR2(5) := '10.40';
    end_time    VARCHAR2(5);
    duration    VARCHAR2(2) := '30';

BEGIN
    SELECT to_char(to_date(start_time, 'HH24.MI') + INTERVAL duration MINUTE, 'HH24:MI')
    INTO end_time
    FROM dual;
END;

...I just get an ORA-00907 (missing right parenthesis). Playing around with it seems to imply that it doesn't like the use of the variable "duration" and only works if I hard code a value.

Is it possible to do what I'm trying to do and have a variable as the duration field?

Thanks very much
Dagon (MIS)
7 Nov 11 8:48
I'm not sure you can use variables in the INTERVAL stuff.  The simple workaround is to change your number of minutes into a fraction of a day and add that e.g.

CODE

select sysdate + 30/(24*60) from dual
 

slicendice (Programmer)
7 Nov 11 9:08
Yep, I think that's the best/easiest way to do it.

Thanks Dagon

Reply To This Thread

Posting in the Tek-Tips forums is a member-only feature.

Click Here to join Tek-Tips and talk with other members!

Close Box

Join Tek-Tips® Today!

Join your peers on the Internet's largest technical computer professional community.
It's easy to join and it's free.

Here's Why Members Love Tek-Tips Forums:

Register now while it's still free!

Already a member? Close this window and log in.

Join Us             Close