473,320 Members | 1,846 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

Timestamps and computing aggregate time.

Bob
thanks in advance,
I am using Oracle 9i. I am looping through records via plsql and
subtracting 2 timestamp datatypes.

myTime := (disconTime - startTime);

my problem is I dont understand how to get an aggregated variable out
of myTime. What I want is a total amount of time used. I would like to
be able to get it in minutes if possible.

so for example what I get as output from the above is as follows:

+000000000 00:01:01.400000
+000000000 00:01:45.500000
+000000000 00:00:19.700000
+000000000 00:09:38.200000
+000000000 00:01:18.800000
+000000000 00:00:34.100000
+000000000 00:00:43.500000
+000000000 00:01:12.100000
+000000000 00:01:04.500000
+000000000 00:03:00.800000
+000000000 00:02:12.200000

how can I add these up for a grand total of time used?
Jul 19 '05 #1
1 6037
Bob
rg*****@aol.com (Bob) wrote in message news:<ee**************************@posting.google. com>...
thanks in advance,
I am using Oracle 9i. I am looping through records via plsql and
subtracting 2 timestamp datatypes.

myTime := (disconTime - startTime);

my problem is I dont understand how to get an aggregated variable out
of myTime. What I want is a total amount of time used. I would like to
be able to get it in minutes if possible.

so for example what I get as output from the above is as follows:

+000000000 00:01:01.400000
+000000000 00:01:45.500000
+000000000 00:00:19.700000
+000000000 00:09:38.200000
+000000000 00:01:18.800000
+000000000 00:00:34.100000
+000000000 00:00:43.500000
+000000000 00:01:12.100000
+000000000 00:01:04.500000
+000000000 00:03:00.800000
+000000000 00:02:12.200000

how can I add these up for a grand total of time used?


I have the following solution figured out. In short what I am doing is
extracting elements of the timestamp and converting to a number and
changing to seconds. This should work fine now that I have a number.
The trouble was with trying to aggregate an interval.

I am migrating from a sybase environment, in sybase using a datediff
in milliseconds solved the problem. It does not seem like oracle has a
similar function.
CREATE OR REPLACE FUNCTION addem(startDateIn IN timestamp,disconDateIn
IN timestamp) RETURN NUMBER

IS
duration INTERVAL DAY TO SECOND;
myHour NUMBER;
myMinute NUMBER;
mySecond NUMBER;
totalSeconds NUMBER;
BEGIN
duration := (disconDateIn - startDateIn);

myHour := (to_number(extract(HOUR FROM duration))*3600);
myMinute := (to_number(extract(MINUTE FROM duration))*60);
mySecond := to_number(extract(SECOND FROM duration));

--dbms_output.put_line ('Hours as a number : '|| myHour);
--dbms_output.put_line ('Minutes as a number : '|| myMinute);
--dbms_output.put_line ('Secs as a number : '|| mySecond);

totalSeconds := (myHour + myMinute + mySecond);
dbms_output.put_line ('Total Seconds Used: '|| totalSeconds);
return(totalSeconds);
END;
/
Jul 19 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

7
by: lkrubner | last post by:
This might be an idiot question, but how do you group by timestamps by date? I mean, given a large number of timestamps, spanning many months, how do grab them and say how many are from each day?...
2
by: Greg Stark | last post by:
I find I often want to be able to do joins against views where the view are aggregates on a column that has an index. Ie, something like SELECT a.*, v.n FROM a JOIN (select a_id,count(*) as n...
4
by: Craig G | last post by:
im not too sure how i should be storing the SQL2000 timestamps basically i return a dataset which is used to populate an editable grid. this dataset contains the timestamp. how should i be...
1
by: Najib Abi Fadel | last post by:
Hi i have an ordered table of dates let's say: 1/1/2004 8/1/2004 15/1/2004 29/1/2004 5/2/2004 12/2/2004
16
by: maruk2 | last post by:
I have some old data files with old timestamps, where timestmap=time(NULL), some of them date back to the year 1999. I want to my code to print the timestamps and each one to include...
1
by: maruk2 | last post by:
I have some old data files with old timestamps, where timestmap=time(NULL), some of them date back to the year 1999. I want my code to print the timestamps and each one to include...
1
by: Sandro997 | last post by:
Ok. I have a bit of a dilemma here. First, please consider the following function: CREATE OR REPLACE FUNCTION recent_lab(text, labs, treatments) RETURNS float8 AS $BODY$select...
14
by: Aaron Watters | last post by:
So, in between skiing runs I noticed a Business Week cover story on "cloud computing". The article had lots of interesting information in it like about how somebody's mom used to be an airline...
1
by: Bob | last post by:
thanks in advance, I am using Oracle 9i. I am looping through records via plsql and subtracting 2 timestamp datatypes. myTime := (disconTime - startTime); my problem is I dont understand...
0
by: DolphinDB | last post by:
The formulas of 101 quantitative trading alphas used by WorldQuant were presented in the paper 101 Formulaic Alphas. However, some formulas are complex, leading to challenges in calculation. Take...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.