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: David Taft <oradbt054_at_gmail.com>
Date: Thu, 11 Oct 2007 13:58:08 -0400
Message-ID: <69b058e80710111058w60191638g8938760712c2eb6a@mail.gmail.com>


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> wrote:

> On 10/11/07, Rumpi Gravenstein <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 Thu Oct 11 2007 - 12:58:08 CDT

Original text of this message

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