The zero_divide exception is an predefined exception of PL/SQL language and catch error when pl/sql program attempts to divide a number by zero.
Zero_divide example 1
declare v_sum number := 10; v_divide number := 0; v_result number; begin v_result := v_sum / v_divide; dbms_output.put_line('v_result: '||v_result); exception when zero_divide then dbms_output.put_line('ZERO_DIVIDE: '||sqlerrm); end;
Output:
ZERO_DIVIDE: ORA-01476: divisor is equal to zero
Zero_divide example 2
declare v_sum number := 10; v_divide number := 2; v_result number; begin v_result := v_sum / v_divide; dbms_output.put_line('v_result: '||v_result); exception when zero_divide then dbms_output.put_line('ZERO_DIVIDE: '||sqlerrm); end;
Output:
v_result: 5