Solved

Minutes(Number Column) to HH24MM

Posted on 2000-05-15
8
644 Views
Last Modified: 2008-03-17
Good Morning

Have a table with a defined column elapsed_time(number).

example 90 minutes

I want to convert it to HH24MM.

example 0130

Is this possible in Oracle 8i.

Thanks
0
Comment
Question by:tomatocans
8 Comments
 
LVL 5

Expert Comment

by:sbenyo
Comment Utility
There is no time datatype in oracle but you can change the field to a date field like this:

alter table <table-name> modify (elapsed_time date);

Then insert values like this:

insert into <table-name> values (to_date('0130','HH24MI'));

This will store the time value.
If you want to make comparisions on it also use the same format:

select * from <table-name> where elapsed_time > to_date('0230','HH24MI');


0
 

Author Comment

by:tomatocans
Comment Utility
what if u have 60,000 records with elapsed time
fields u need to update
0
 
LVL 34

Expert Comment

by:Mark Geerlings
Comment Utility
There is also another issue.  Oracle date columns always contain a date value, whether they contain the time protion or not.  If you succeed in storing values when you have supplied only the time (I am not sure that Oracle will accept that) you may still have problems doing comparisons or arithmetic based on those values if the days are different.  I am assuming that Oracle will use the current sysdate for the date portion, so a record created just before midnight one day will have a different date than a records created moments later after midnight.

Have you tested this?
0
 

Expert Comment

by:erezal
Comment Utility
Why do you want to convert a field
containing elapsed time to a "HH24:MM"
mask?

In what ways are you using the field
(Comparisons,calculations,showing only)?
0
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.

 
LVL 1

Expert Comment

by:nitinpai
Comment Utility
Hi,
  The problem definition is not clear. But from what I have interpreted, u have a column of number datatype which is actually storing the elapsed time. Now, u want to update the values so that it will be in the format hhmi. Ok. Then u can run the following statement:
update tmp
set elapsed_time = floor(elapsed_time/60)||mod(elapsed_time,60);

Note that u cannot have the format 0130 bcos the datatype is a number and not a character.

The above statement will update the value elapsed_time = 90 to elapsed_time = 130. However, if the elapsed_time = 1440 the value will be converted to 240. Now, if the elapsed_time is greater than 24 hrs, what format do u want it to be in?? Pl. give examples. The solution is always available.

0
 
LVL 34

Expert Comment

by:Mark Geerlings
Comment Utility
Have you considered creating a view using a calculation like the one suggested by nitinpai, instead of altering your table?  This has the advantage of not requiring an update, and being able to display all of the records as if they had been updated.

Can you explain the advantage(s) you see in having the data stored as something other than a number?
0
 
LVL 1

Accepted Solution

by:
sohill earned 50 total points
Comment Utility
use this sql :
select to_char(to_date(lpad(trunc(&1/60),2,'0')||lpad(MOD(&1,60),2,'0'),'HH24MI'),'HH24:MI')  
from dual

and subsitute &1 by your parameter, e.g. 90
0
 

Author Comment

by:tomatocans
Comment Utility
Thanks
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.

Join & Write a Comment

Article by: Swadhin
From the Oracle SQL Reference (http://download.oracle.com/docs/cd/B19306_01/server.102/b14200/queries006.htm) we are told that a join is a query that combines rows from two or more tables, views, or materialized views. This article provides a glimps…
Introduction A previously published article on Experts Exchange ("Joins in Oracle", http://www.experts-exchange.com/Database/Oracle/A_8249-Joins-in-Oracle.html) makes a statement about "Oracle proprietary" joins and mixes the join syntax with gen…
This video explains at a high level about the four available data types in Oracle and how dates can be manipulated by the user to get data into and out of the database.
This video shows how to copy an entire tablespace from one database to another database using Transportable Tablespace functionality.

743 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

Need Help in Real-Time?

Connect with top rated Experts

15 Experts available now in Live!

Get 1:1 Help Now