Zero-Divide Assignment Help

Assignment Help: >> Pre-defined Exceptions - Zero-Divide

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.

Free Assignment Quote

Assured A++ Grade

Get guaranteed satisfaction & time on delivery in every assignment order you paid with us! We ensure premium quality solution document along with free turntin report!

All rights reserved! Copyrights ©2019-2020 ExpertsMind IT Educational Pvt Ltd