Friday, March 29, 2013

ORACLE ZERO_DIVIDE EXCEPTION HANDLING

ORACLE ZERO_DIVIDE EXCEPTION HANDLING

           
Zero Divide exception occurs when number divided by zero.

It can be handled with ZERO_DIVIDE or OTHERS in Exception block

declare
a number;
b number;
c number;
begin
a:=10;
b:=0;
c:= a/b;
dbms_output.put_line(a||' '||b||' '||c);
end;

OUTPUT:

SQL> /
declare
*
ERROR at line 1:
ORA-01476: divisor is equal to zero
ORA-06512: at line 8

Handling ZERO_DIVIDE Exception

Method 1:

declare
a number;
b number;
c number;
begin
a:=10;
b:=0;
c:= a/0;
dbms_output.put_line(a||' '||b||' '||c);
exception
when ZERO_DIVIDE then
dbms_output.put_line('ZERO DIVIDE NOT ALLOWED');

end;
/

Method 2:
 Replace ZERO_DIVIDE exception with

exception
When OTHERS then
  dbms_output.put_line('UNKNOWN ERROR');

Tags: ORACLE ZERO_DIVIDE EXCEPTION HANDLING,
Handling ZERO_DIVIDE Exception in PL/SQL, Handling ZERO_DIVIDE exception with OTHERS, Oracle PL/SQL exceptions.

No comments:

Post a Comment