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: SQLPLUS divide by zero question

Re: SQLPLUS divide by zero question

From: Jonathan Gennick <gennick_at_worldnet.att.net>
Date: 26 Aug 1998 02:26:58 GMT
Message-ID: <35e61d1b.3723191@netnews.worldnet.att.net>


On 24 Aug 1998 22:56:29 GMT, iancrozier_at_aol.com (Iancrozier) wrote:

>I am trying to run a sql statement, something like this:
>
>select sum(A)/sum(B) from table T;
>
>Sometimes sum(B) is equal to zero. Is there any way in sqlplus I can run this
>or
>do I have to go to PL/SQL?

You might try:

select decode (sum(b),0,0,sum(a)/sum(b)) from t;

The DECODE will return a zero if the sum(b) evaluates to 0, otherwise it will return your expression.

regards,

Jonathan Gennick Received on Tue Aug 25 1998 - 21:26:58 CDT

Original text of this message

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