How to handle divisor is equal to zero error

While execution the query with arithmetic calculation exception will throw divisor is equal to zero error.In this situation we can use below logic.

CREATE OR REPLACE FUNCTION divisorzero (p_divited NUMBER, p_devisor NUMBER)
RETURN NUMBER
AS
l_value NUMBER;
begin
BEGIN
l_value := p_divited / p_devisor;

EXCEPTION
WHEN OTHERS
THEN
l_value := 0;
END;
return l_value;
end;

select divisorzero(5,0) result from dual

The above query return 0 as result.

Recent Posts