Oracle FAQ Your Portal to the Oracle Knowledge Grid
HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US
 

Home -> Community -> Mailing Lists -> Oracle-L -> Re: CAST vs. TO_NUMBER or TO_CHAR or TO_DATE or ...

Re: CAST vs. TO_NUMBER or TO_CHAR or TO_DATE or ...

From: William Robertson <william_at_williamrobertson.net>
Date: Sat, 13 Oct 2007 18:53:01 +0100
Message-ID: <471105FD.7020800@williamrobertson.net>


Or perhaps

   CAST(diff_time AS INTERVAL DAY(4) TO SECOND(0))

which would give something like

   DIFF_TIME    


   +1528 03:14:22

-----Original message-----
From: David Taft
Date: 11/10/07 18:58
> Looks useful for figuring out things like elapsed time. No doubt
> there are other ways to do the same thing and I'm sure there are many
> other uses for cast. I'm glad to have been made aware of this function.
>
> David
>
> ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
> --Elapsed days and time since object creation and last DDL change.
> col days heading "Elapsed|Days"
> col time heading "Elapsed|Time"
> select
> lpad(extract(day from objtime.diff_time),5) days,
> lpad(extract(hour from objtime.diff_time),2,'0')||':'||
> lpad(extract(minute from objtime.diff_time),2,'0')||':'||
> lpad(extract(second from objtime.diff_time),2,'0') time
> from
> (select cast(LAST_DDL_TIME as timestamp) - cast(CREATED as timestamp)
> diff_time
> from DBA_OBJECTS
> where owner='SYS'
> and object_type='PACKAGE BODY'
> and object_name='DBMS_ALERT') objtime
> /
> Elaps Elapsed
> Days Time
> ----- --------
> 1528 03:14:22
>
>
> On 10/11/07, *Jared Still* <jkstill_at_gmail.com
> <mailto:jkstill_at_gmail.com>> wrote:

>

> On 10/11/07, *Rumpi Gravenstein* < rgravens_at_gmail.com
> <mailto:rgravens_at_gmail.com>> wrote:
>
> I've been looking at the Oracle CAST function vs. a TO_NUMBER
> or TO_CHAR or .... Where both the CAST and TO_ functions
> result in equivalent answers, is there a preferred choice?
>
> >
> CAST() is clearly faster than TO_DATE, and more robust as well.
>
> There may be other advantages to using it.
> -- http://www.freelists.org/webpage/oracle-l
Received on Sat Oct 13 2007 - 12:53:01 CDT

Original text of this message

HOME | ASK QUESTION | ADD INFO | SEARCH | E-MAIL US