RE: How to calculate time using SQL

2002-04-01 Thread Nguyen, David M

Thanks for your advices, Stephane.

David

-Original Message-
Sent: Monday, April 01, 2002 12:19 PM
To: Multiple recipients of list ORACLE-L


"Nguyen, David M" wrote:
> 
> Jack,
> 
> How about substracting a system date with a database replication date to
get
> difference of time?  Can you please give me a specific command?
> 
> SQL> select to_char(sysdate, 'Dy Mon Dd HH24:MI:SS ') from dual;
> 
> TO_CHAR(SYSDATE,'DYMONDD
> 
> Mon Apr 01 11:08:00 2002==> System Time.
> 
> SQL> select next_date from user_refresh;
> 
> NEXT_DATE
> 
> Mon Apr 01 11:11:01 2002  ==> Replication time.
> 
> Thanks,
> David
> 

David,

   If what you are after is measuring the lag between two replicated
databases, you may have to do something slightly more complicated. For
one thing, do not forget that system time is, most often that note, time
read by the system-engineer on his wrist-watch the last time he set the
date. If your machines do not take the time from a common source, you
may get a pessimistic or optimistic view, depending on the machine you
are looking at. I think that it's better to look how long it takes to
replicate from A to B and back - it will allow you to compare a A
timestamp to another A timestamp. Dividing by 2 will give you a fair if
not absolutely correct assessment of how long it takes to go from A to B
or B to A.
 Also, a good way to check how replication goes is to create a dummy
table with three columns, A_TIME_START, B_TIME and A_TIME_FINISH, to
store (on A) SYSDATE into A_TIME_START, to let replicate and have
triggers inserting SYSDATE into the ad hoc column everytime it reaches a
node.

HTH,

Stephane Faroult
Oriole Software
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Stephane Faroult
  INET: [EMAIL PROTECTED]

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Nguyen, David M
  INET: [EMAIL PROTECTED]

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).



RE: How to calculate time using SQL

2002-04-01 Thread Nguyen, David M

It works.  Thank you so much, Jack.

David

-Original Message-
Sent: Monday, April 01, 2002 10:38 AM
To: Multiple recipients of list ORACLE-L


David,

Select (DateTime1 - DateTime2) * 24 * 60 * 60
>From   Dual
;

Oracle date arithmetic results are in fractional days, so the above gets you
the number of seconds between two Date datatype arguments.  Of course you
can go ahead and multiply 24*60*60 to get Seconds/Day, but I prefer to leave
it that way so it's more obvious what my intent is.

Jack

Jack C. Applewhite
Database Administrator/Developer
OCP Oracle8 DBA
iNetProfit, Inc.
Austin, Texas
www.iNetProfit.com
[EMAIL PROTECTED]
(512)327-9068


-Original Message-
David M
Sent: Monday, April 01, 2002 9:48 AM
To: Multiple recipients of list ORACLE-L


Is it possible to calculate seconds using SQL?

For example, I'd like to subtract   these two time to get difference in
seconds:

10:20:32  -   10:25:29

Thanks,
David



-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Jack C. Applewhite
  INET: [EMAIL PROTECTED]

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Nguyen, David M
  INET: [EMAIL PROTECTED]

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).



Re: How to calculate time using SQL

2002-04-01 Thread Stephane Faroult

"Nguyen, David M" wrote:
> 
> Jack,
> 
> How about substracting a system date with a database replication date to get
> difference of time?  Can you please give me a specific command?
> 
> SQL> select to_char(sysdate, 'Dy Mon Dd HH24:MI:SS ') from dual;
> 
> TO_CHAR(SYSDATE,'DYMONDD
> 
> Mon Apr 01 11:08:00 2002==> System Time.
> 
> SQL> select next_date from user_refresh;
> 
> NEXT_DATE
> 
> Mon Apr 01 11:11:01 2002  ==> Replication time.
> 
> Thanks,
> David
> 

David,

   If what you are after is measuring the lag between two replicated
databases, you may have to do something slightly more complicated. For
one thing, do not forget that system time is, most often that note, time
read by the system-engineer on his wrist-watch the last time he set the
date. If your machines do not take the time from a common source, you
may get a pessimistic or optimistic view, depending on the machine you
are looking at. I think that it's better to look how long it takes to
replicate from A to B and back - it will allow you to compare a A
timestamp to another A timestamp. Dividing by 2 will give you a fair if
not absolutely correct assessment of how long it takes to go from A to B
or B to A.
 Also, a good way to check how replication goes is to create a dummy
table with three columns, A_TIME_START, B_TIME and A_TIME_FINISH, to
store (on A) SYSDATE into A_TIME_START, to let replicate and have
triggers inserting SYSDATE into the ad hoc column everytime it reaches a
node.

HTH,

Stephane Faroult
Oriole Software
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Stephane Faroult
  INET: [EMAIL PROTECTED]

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).



Re: How to calculate time using SQL

2002-04-01 Thread John Carlson

Here is a script I recently made to help me understand how the date worked.

>>
REM Elapsed Time

define start_time = '03-25-02 11:17:12'
define stop_time  = '03-27-02 12:36:30'
define date_fmt   = 'mm-dd-yy hh24:mi:ss'

select trunc(to_date('&&stop_time', '&&date_fmt')
  - to_date('&&start_time', '&&date_fmt')) "Elapsed: Days",
trunc(mod((to_date('&&stop_time', '&&date_fmt')
  - to_date('&&start_time', '&&date_fmt')),1) * 24) "Hours",
trunc(mod( 24 * (to_date('&&stop_time', '&&date_fmt')
  - to_date('&&start_time', '&&date_fmt')),1) * 60) "Minutes",
mod( (24*60) * (to_date('&&stop_time', '&&date_fmt')
  - to_date('&&start_time', '&&date_fmt')),1) * 60 "Seconds"
from dual
/

-- The following show how the above query is broken down.
-- The mod or remainder of each calc is multipled to get time.

select (to_date('&&stop_time', '&&date_fmt')
- to_date('&&start_time', '&&date_fmt')) "Elapsed Days"
from dual
/

select (24) * (to_date('&&stop_time', '&&date_fmt')
- to_date('&&start_time', '&&date_fmt')) "Elapsed Hours"
from dual
/

select (60*24) * (to_date('&&stop_time', '&&date_fmt')
- to_date('&&start_time', '&&date_fmt')) "Elapsed Minutes"
from dual
/

select (60*60*24) * (to_date('&&stop_time', '&&date_fmt')
- to_date('&&start_time', '&&date_fmt')) "Elapsed Seconds"
from dual
/

<<

Run it and see how it works and then experiment yourself.  One thing I haven't tried 
is 's'.  The book says it is 'seconds past midnight'.  I guess if you had a job 
that never ran past midnight, you could just subtract the begining time from the end 
time and get seconds that way.

Of course, you can 'set timing on' but that is only good for each step.  If you have a 
job that has several sql statements and you want to get the total time, you need 
something like what I have done.

HTH,
John


>>> [EMAIL PROTECTED] 04/01/02 07:48AM >>>
Is it possible to calculate seconds using SQL?  

For example, I'd like to subtract   these two time to get difference in
seconds:

10:20:32  -   10:25:29

Thanks,
David
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com 
-- 
Author: Nguyen, David M
  INET: [EMAIL PROTECTED] 

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).

--
Please see the official ORACLE-L FAQ: http://www.orafaq.com
--
Author: John Carlson
  INET: [EMAIL PROTECTED]

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).



RE: How to calculate time using SQL

2002-04-01 Thread Jack C. Applewhite

David,

SysDate is a function and can be referenced in any SQL statement.  So you
could do the following if you want seconds between the two, or leave off
some or all of the trailing multiplicands to get fractional minutes, hours
or days.

Select ( SysDate - Next_Date ) * 24 * 60 * 60
>From   User_Refresh
;

You need to do a little reading in the Oracle SQL Reference under Datatypes
to find out details of the Date datatype and Date arithmetic.

Jack


Jack C. Applewhite
Database Administrator/Developer
OCP Oracle8 DBA
iNetProfit, Inc.
Austin, Texas
www.iNetProfit.com
[EMAIL PROTECTED]
(512)327-9068


-Original Message-
David M
Sent: Monday, April 01, 2002 11:42 AM
To: Multiple recipients of list ORACLE-L


Jack,

How about substracting a system date with a database replication date to get
difference of time?  Can you please give me a specific command?


SQL> select to_char(sysdate, 'Dy Mon Dd HH24:MI:SS ') from dual;

TO_CHAR(SYSDATE,'DYMONDD

Mon Apr 01 11:08:00 2002==> System Time.


SQL> select next_date from user_refresh;

NEXT_DATE

Mon Apr 01 11:11:01 2002  ==> Replication time.

Thanks,
David




-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Jack C. Applewhite
  INET: [EMAIL PROTECTED]

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).



RE: How to calculate time using SQL

2002-04-01 Thread Nguyen, David M

Jack,

How about substracting a system date with a database replication date to get
difference of time?  Can you please give me a specific command?  


SQL> select to_char(sysdate, 'Dy Mon Dd HH24:MI:SS ') from dual;

TO_CHAR(SYSDATE,'DYMONDD

Mon Apr 01 11:08:00 2002==> System Time.


SQL> select next_date from user_refresh;

NEXT_DATE

Mon Apr 01 11:11:01 2002  ==> Replication time.

Thanks,
David



-Original Message-
Sent: Monday, April 01, 2002 10:38 AM
To: Multiple recipients of list ORACLE-L


David,

Select (DateTime1 - DateTime2) * 24 * 60 * 60
>From   Dual
;

Oracle date arithmetic results are in fractional days, so the above gets you
the number of seconds between two Date datatype arguments.  Of course you
can go ahead and multiply 24*60*60 to get Seconds/Day, but I prefer to leave
it that way so it's more obvious what my intent is.

Jack

Jack C. Applewhite
Database Administrator/Developer
OCP Oracle8 DBA
iNetProfit, Inc.
Austin, Texas
www.iNetProfit.com
[EMAIL PROTECTED]
(512)327-9068


-Original Message-
David M
Sent: Monday, April 01, 2002 9:48 AM
To: Multiple recipients of list ORACLE-L


Is it possible to calculate seconds using SQL?

For example, I'd like to subtract   these two time to get difference in
seconds:

10:20:32  -   10:25:29

Thanks,
David



-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Jack C. Applewhite
  INET: [EMAIL PROTECTED]

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Nguyen, David M
  INET: [EMAIL PROTECTED]

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).



Re: How to calculate time using SQL

2002-04-01 Thread Viktor

Try this:

select to_date('10:20:32','hh:mi:ss') -
to_date('10:25:29', 'hh:mi:ss')
from dual
/

Viktor

--- "Nguyen, David M" <[EMAIL PROTECTED]> wrote:
> Is it possible to calculate seconds using SQL?  
> 
> For example, I'd like to subtract   these two time
> to get difference in
> seconds:
> 
> 10:20:32  -   10:25:29
> 
> Thanks,
> David
> -- 
> Please see the official ORACLE-L FAQ:
> http://www.orafaq.com
> -- 
> Author: Nguyen, David M
>   INET: [EMAIL PROTECTED]
> 
> Fat City Network Services-- (858) 538-5051  FAX:
> (858) 538-5051
> San Diego, California-- Public Internet
> access / Mailing Lists
>

> To REMOVE yourself from this mailing list, send an
> E-Mail message
> to: [EMAIL PROTECTED] (note EXACT spelling of
> 'ListGuru') and in
> the message BODY, include a line containing: UNSUB
> ORACLE-L
> (or the name of mailing list you want to be removed
> from).  You may
> also send the HELP command for other information
> (like subscribing).


__
Do You Yahoo!?
Yahoo! Greetings - send holiday greetings for Easter, Passover
http://greetings.yahoo.com/
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Viktor
  INET: [EMAIL PROTECTED]

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).



RE: How to calculate time using SQL

2002-04-01 Thread Jack C. Applewhite

David,

Select (DateTime1 - DateTime2) * 24 * 60 * 60
>From   Dual
;

Oracle date arithmetic results are in fractional days, so the above gets you
the number of seconds between two Date datatype arguments.  Of course you
can go ahead and multiply 24*60*60 to get Seconds/Day, but I prefer to leave
it that way so it's more obvious what my intent is.

Jack

Jack C. Applewhite
Database Administrator/Developer
OCP Oracle8 DBA
iNetProfit, Inc.
Austin, Texas
www.iNetProfit.com
[EMAIL PROTECTED]
(512)327-9068


-Original Message-
David M
Sent: Monday, April 01, 2002 9:48 AM
To: Multiple recipients of list ORACLE-L


Is it possible to calculate seconds using SQL?

For example, I'd like to subtract   these two time to get difference in
seconds:

10:20:32  -   10:25:29

Thanks,
David



-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Jack C. Applewhite
  INET: [EMAIL PROTECTED]

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).



How to calculate time using SQL

2002-04-01 Thread Nguyen, David M

Is it possible to calculate seconds using SQL?  

For example, I'd like to subtract   these two time to get difference in
seconds:

10:20:32  -   10:25:29

Thanks,
David
-- 
Please see the official ORACLE-L FAQ: http://www.orafaq.com
-- 
Author: Nguyen, David M
  INET: [EMAIL PROTECTED]

Fat City Network Services-- (858) 538-5051  FAX: (858) 538-5051
San Diego, California-- Public Internet access / Mailing Lists

To REMOVE yourself from this mailing list, send an E-Mail message
to: [EMAIL PROTECTED] (note EXACT spelling of 'ListGuru') and in
the message BODY, include a line containing: UNSUB ORACLE-L
(or the name of mailing list you want to be removed from).  You may
also send the HELP command for other information (like subscribing).