Oracle FAQ | Your Portal to the Oracle Knowledge Grid |
![]() |
![]() |
Home -> Community -> Usenet -> c.d.o.server -> Re: How to eliminate divide by zero error
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.comReceived on Thu Mar 08 2007 - 19:50:54 CST
![]() |
![]() |