sql – Error: divisor equals zero in Oracle

Question:

I need to perform the following SQL query in ORACLE :

select 
        (DISPONIBILIDADES/EFECTIVO) as DISPONIBLE
    from sbv 
    where banco = 'ACTIVO (BU)'

But I get the following error:

ORA-01476: the divisor is equal to zero 01476. 00000 – "divisor is equal to zero"

The EFECTIVO field has a value of 0. I know that a division by 0 gives an indeterminacy but I need that if the division is by 0, it gives me 0 as a result.

Answer:

For this we can use a case to first make the division check that the value is not 0.

select 
CASE EFECTIVO 
    WHEN 0 THEN 0
    ELSE (DISPONIBILIDADES/EFECTIVO) END as DISPONIBLE
from sbv 
where banco = 'ACTIVO (BU)'
Scroll to Top