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:Numeric comparison in DECODE statement

Re:Numeric comparison in DECODE statement

From: <Brian_P_MacLean_at_eFunds.Com>
Date: Mon, 20 May 2002 08:33:34 -0800
Message-ID: <F001.00464AD1.20020520083334@fatcity.com>

You can do numeric logic by using the SIGN() function. Here is the solution I think he was looking for:

SQL_at_sandbox:test:8.1.7:OPS$ORACLE:12,34570>r   1 select ltrim(decode(sign(minutes - 59), 1, to_char(minutes/60, '9.99') ||' hours',

  2                                             to_char(minutes)||'
minutes'
  3                     )
  4              ) TIME

  5 from bart
  6* order by minutes

TIME



13 minutes
55 minutes
1.08 hours
3.50 hours

SQL_at_sandbox:test:8.1.7:OPS$ORACLE:12,34570>select * from bart order by 1;

  MINUTES


       13
       55
       65
      210




Brian P. MacLean
Oracle DBA, OCP8i

                                                                                                                                       
                      dgoulet_at_vicr.com                                                                                                 
                      Sent by:                 To:       Multiple recipients of list ORACLE-L <ORACLE-L_at_fatcity.com>                   
                      root_at_fatcity.com         cc:                                                                                     
                                               Subject:  Re:Numeric comparison in DECODE statement                                     
                                                                                                                                       
                      05/20/02 08:38 AM                                                                                                
                      Please respond to                                                                                                
                      ORACLE-L                                                                                                         
                                                                                                                                       
                                                                                                                                       




Robert,

    That won't work. Decode works like a switch statement. If condition 1 then
value 1. You can't imbed logic operators therein.

DickG.

____________________Reply Separator____________________
Author: Yexley Robert D Contr Det 1 AFRL/WSI <Robert.Yexley_at_wpafb.af.mil>
Date:       5/20/2002 7:08 AM

I was wondering if anyone might have tried this before, because I can't seem to
get it to work. I'd like to be able to determine which unit of measure to concatenate to a value by using a decode statement in the query. I have a column in the database that stores time in minutes, and I'd like to be able to
show the output in minutes if the value is less than 60, but in hours (such as
3.27 hours) if the value is greater than 60. So far I've tried the following
statement, but it seems to be blowing up on the first comparison operator:

SELECT decode(in_value, to_char(to_number(in_value) <= to_number('60')), to_char(in_value)||' minutes', to_char(to_number(in_value) > to_number ('60')),
to_char(in_value/60, '9.99')||' hours')
  FROM dual
/

I'm selecting from dual just until I can get the query working at all. Is what
I'm trying to do even possible? Any help or ideas would be greatly appreciated.
 Thanks in advance.

_YEX_
/*

|| Robert D. Yexley
|| Oracle Programmer/Analyst
|| Easylink Services Corporation
|| Professional Services
|| Contractor - Wright Research Site MIS
|| Det-1 AFRL/WSI Bldg. 45 Rm. 062
|| (937) 255-1984
|| robert.yexley_at_wpafb.af.mil
|| <)))><

*/
--
Please see the official ORACLE-L FAQ: http://www.orafaq.com
--
Author: Yexley Robert D Contr Det 1 AFRL/WSI
  INET: Robert.Yexley_at_wpafb.af.mil

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: ListGuru_at_fatcity.com (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:
  INET: dgoulet_at_vicr.com

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: ListGuru_at_fatcity.com (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: 
  INET: Brian_P_MacLean_at_eFunds.Com

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: ListGuru_at_fatcity.com (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).
Received on Mon May 20 2002 - 11:33:34 CDT

Original text of this message

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