Home » SQL & PL/SQL » SQL & PL/SQL » zero divide error...
zero divide error... [message #38526] Wed, 24 April 2002 15:18 Go to next message
shreya
Messages: 15
Registered: March 2001
Junior Member
Hi ,

My query is like this.

SELECT a.* FROM schema1.table1@dlink1 a,schema2.table2@dlink2 b
WHERE ABS((a.amount-b.amount))/a.amount >= 0.05
AND a.id = b.id ;

If a.amount is 0 it will give the following error.
ORA-01476: divisor is equal to zero

Does anyone have any idea how to get rid of this problem.
I tried including a.amount!=0 in the where clause but what if b.amount is having some value.

Thanks in advance,
Shreya.
Re: zero divide error... [message #38528 is a reply to message #38526] Wed, 24 April 2002 16:11 Go to previous messageGo to next message
Todd Barry
Messages: 4819
Registered: August 2001
Senior Member
Could you do something like:

WHERE ABS(a.amount - b.amount) / decode(a.amount, 0, 1, a.amount) >= 0.05


Basically replace a value of 0 with 1...
Re: zero divide error... [message #38530 is a reply to message #38526] Wed, 24 April 2002 17:17 Go to previous messageGo to next message
shreya
Messages: 15
Registered: March 2001
Junior Member
Hi Todd,

It worked thanks very much.

Shreya.
Re: zero divide error... [message #38534 is a reply to message #38526] Thu, 25 April 2002 04:16 Go to previous messageGo to next message
John R
Messages: 156
Registered: March 2000
Senior Member
Or, to avoid returning rows where a.amount is 0, which this solution will do if abs(b.amount) >= 0.05, try

WHERE ABS(a.amount - b.amount)/decode(a.amount,0,b.amount*30,a.amount) >= 0.05

Also, are you sure the ABS shouldn't go round the whole calculation - the way it is currently written it will not return any rows where A.amount < 0
Re: zero divide error... [message #38538 is a reply to message #38526] Thu, 25 April 2002 09:08 Go to previous message
shreya
Messages: 15
Registered: March 2001
Junior Member
Hi John,

It should work for all conditions
i.e if a.amount is<0 also it should work. I didn't try for that condition. If u are sure it doesn't work for a.amount<0 then please send me the query that works for <0 condition.

Thanks very much,
Shreya.
Previous Topic: Count of updated rows...
Next Topic: Code works but don't like extra burden when calling procedure.
Goto Forum:
  


Current Time: Fri Apr 19 11:45:12 CDT 2024