Zero-Divide:
When a number is divided by zero, the zero divide exception is raised. The given example briefs this exception.
Example
DECLARE
X NUMBER:=&X;
Y NUMBER:=&Y;
BEGIN
DBMS_OUTPUT.PUT_LINE('RESULT IS '||X/Y);
END;
In this instance, two values are accepted for x and y correspondingly. If both contain non-zero values the result is printed. If 'y' holds zero, it leads to the exception that is displayed as:
ORA-01476: divisor is equal to zero
In order to handle the exception, exception clause must hold the Exception Zero_Divide. Refining the above instance,
DECLARE
X NUMBER:=&X;
Y NUMBER:=&Y; BEGIN
DBMS_OUTPUT.PUT_LINE('RESULT IS '||X/Y);
EXCEPTION
WHEN ZERO_DIVIDE THEN
DBMS_OUTPUT.PUT_LINE('VALUE IS DIVIDED BY ZERO');
END;
The second example describes the usage of NO_DATA_FOUND
Example
DECLARE
MYENAME VARCHAR2(20);
BEGIN
SELECT ENAME INTO MYENAME FROM EMP WHERE EMPNO=&X;#for selecting ENAME from employee table which employee no is =&X#
DBMS_OUTPUT.PUT_LINE('THE NAME OF THE EMPLOYEE IS '||MYENAME);
EXCEPTION
WHEN NO_DATA_FOUND THEN
DBMS_OUTPUT.PUT_LINE('NO RECORD FOUND');
END;
/
A SELECT statement returns not more than one row. A cursor is needs if a SELECT statement is made to return more than one record.