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

Home -> Community -> Usenet -> c.d.o.server -> Re: How to eliminate divide by zero error

Re: How to eliminate divide by zero error

From: Brian Peasland <dba_at_nospam.peasland.net>
Date: Thu, 08 Mar 2007 19:50:54 -0600
Message-ID: <45f0b0d1$0$16287$88260bb3@free.teranews.com>


D wrote:
> Hello - I'm looking to eliminate the divide by zero error using
> coalesce on the following code. Not sure how to incorporate on
> another
> function. Please help!!
>
> (round((case when(d.NUM_INC)=0 then 0 else (d.DUR_INC-
> d.IN_WRAPUP_TIME-
> d.DUR_HOLD)/d.NUM_INC end),0)/round(((case when(d.NUM_INC)=0 then 0
> else (d.DUR_INC-d.IN_WRAPUP_TIME-d.DUR_HOLD)/d.NUM_INC end + case
> when(d.NUM_INC)=0 then 0 else d.DUR_HOLD/d.NUM_INC end + case
> when(d.NUM_INC)=0 then 0 else (d.OUT_WRAPUP_TIME+d.IN_WRAPUP_TIME)/
> d.NUM_INC end)),0))
>

The DECODE function is useful here. Assume you are going to divide x by y. Then the following DECODE will show that result unless y=0, and then it will show something else:

DECODE(y,0,'N/A',x/y)

You'll have to decide what the output will be if y is zero.

Either that, or consider eliminating those rows where y=0 by including:

WHERE y<>0

in your SQL statement.

HTH,
Brian

-- 
===================================================================

Brian Peasland
dba_at_nospam.peasland.net
http://www.peasland.net

Remove the "nospam." from the email address to email me.


"I can give it to you cheap, quick, and good.
Now pick two out of the three" - Unknown

-- 
Posted via a free Usenet account from http://www.teranews.com
Received on Thu Mar 08 2007 - 19:50:54 CST

Original text of this message

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