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

  • From: William Robertson <william@xxxxxxxxxxxxxxxxxxxx>
  • To: oracle-l <oracle-l@xxxxxxxxxxxxx>
  • Date: Sat, 13 Oct 2007 18:53:01 +0100

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

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


--
//www.freelists.org/webpage/oracle-l


Other related posts: