ORA-01476: “divisor is equal to zero” handle error in SQL query

Please try the following thing in your SQL query to fix the error:

The error occurs when we face the 0 value on the divisor side, then we will get an error.

SQL> select 1/0 from dual;
select 1/0 from dual
*
ERROR at line 1:
ORA-01476: divisor is equal to zero

To overcome this issue, we will use a case or nullif statement to handle the 0 value before this situation occurs

Use of case statement — the case will check whether that the divisor is 0 or not then it will not calculate if it is 0

-- Case Statement
case when value2 <> 0 then value1 / value2 * 100 else null end

Use of nullif statement — Nullif changes the 0 value to null so, it does not calculate anything

value1 / nullif(value2, 0) * 100
This entry was posted in Oracle on by .
Unknown's avatar

About SandeepSingh

Hi, I am working in IT industry with having more than 15 year of experience, worked as an Oracle DBA with a Company and handling different databases like Oracle, SQL Server , DB2 etc Worked as a Development and Database Administrator.

Leave a Reply