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

Home -> Community -> Usenet -> c.d.o.misc -> Re: How To Avoid Divide by Zero?

Re: How To Avoid Divide by Zero?

From: Pierre Charpenay <pcharpenay_at_unilog.fr>
Date: Wed, 08 Dec 1999 14:05:49 +0100
Message-ID: <384E57AD.E2F5AB63@unilog.fr>

Lee Kyoung Rok wrote :

>
> Change
> (HEADWATER - TAILWATER) / 100
> to
> (HEADWATER - DECODE(TAILWATER,HEADWATER,NULL,TAILWATER,TAILWATER))/100
Some remarks :

  1. That's OK, but, if it happens, the sum will be NULL ! I think 0 (zero) is a better solution. In that case, replace : ( (WATER_SURFACE - TAILWATER) / ((HEADWATER - TAILWATER) / 100) ) by DECODE(HEADWATER, TAILWATER, 0, (WATER_SURFACE - TAILWATER) / ((HEADWATER - TAILWATER) / 100) )
  2. On every line, you used decode(instrument_name, '01-1',...), but, according to the selection clause, this will be always true (fortunately, because if it isn't, the decode and the sum will be NULL). So it seems that it's unusefull.
  3. The sixth line seems to be a percentage, are you sure you want to add them ? An average can't be more significative (for the other lines too)? In that case, you just have to divide each sum by a count(*) ou use the avg() instead of sum().

Regards

Pierre Received on Wed Dec 08 1999 - 07:05:49 CST

Original text of this message

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