Home » SQL & PL/SQL » SQL & PL/SQL » divisor is equal to zero error (Oracle 11g)
divisor is equal to zero error [message #628389] Mon, 24 November 2014 13:22 Go to next message
kkeebler
Messages: 1
Registered: November 2014
Location: New York
Junior Member
I'm relative new to programming in Oracle SQL and I cannot seem to figure out how to deal with the "divisor is equal to zero" error. Here is a sample of my code with generic table and column names. Can anyone explain why my case statement does not solve the error?


SELECT table1.column1, 
       table1.column2, 
       table1.column3, 
       table1.column4, 
       SUM(CASE 
             WHEN ( 1 - table1.age4 ) <= 1 THEN 0 
             WHEN ( 1 - table1.age4 ) > 1 THEN ( ( table2.age5 ) * ( 1 / 
                                                 ( 1 - table1.age4 ) ) ) 
             ELSE 0 
           END) AS COLUMN5 
FROM   table1 
       inner join table2 
               ON table2.column1 = table1.column1 
GROUP  BY table1.column1, 
          table1.column2, 
          table1.column3, 
          table1.column4 
ORDER  BY table1.column1, 
          table1.column2, 
          table1.column3, 
          table1.column4; 

*BlackSwan formatted SQL. Please do so yourself in the future.

[Updated on: Mon, 24 November 2014 13:25] by Moderator

Report message to a moderator

Re: divisor is equal to zero error [message #628390 is a reply to message #628389] Mon, 24 November 2014 13:22 Go to previous messageGo to next message
BlackSwan
Messages: 26766
Registered: January 2009
Location: SoCal
Senior Member
Welcome to this forum

Please read and follow the forum guidelines, to enable us to help you:

http://www.orafaq.com/forum/t/88153/0/ and read http://www.orafaq.com/forum/t/174502/
Re: divisor is equal to zero error [message #628391 is a reply to message #628389] Mon, 24 November 2014 13:33 Go to previous message
Michel Cadot
Messages: 68645
Registered: March 2007
Location: Nanterre, France, http://...
Senior Member
Account Moderator

It works well for me:
SQL> select case when 1-1 <= 1 then 0
  2              when 1-1 > 1 then 2 * ( 1 / (1-1) )
  3              else 0
  4         end val
  5  from dual;
       VAL
----------
         0

So post something we can reproduce: a working Test case: create table (including all constraints) and insert statements along with the result you want with these data then we will be able work with your table and data.
Before, Please read How to use [code] tags and make your code easier to read.

Previous Topic: Sql Satement print list of string
Next Topic: PL/SQL email config
Goto Forum:
  


Current Time: Fri Apr 26 12:23:51 CDT 2024