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

  • From: "David Taft" <oradbt054@xxxxxxxxx>
  • To: jkstill@xxxxxxxxx
  • Date: Thu, 11 Oct 2007 13:58:08 -0400

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

> On 10/11/07, Rumpi Gravenstein <rgravens@xxxxxxxxx> 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.

Other related posts: