7.1.1 Understanding the Importance of Error HandlingIn this exercise, you will calculate the value of the square root of a number and display it on the screen. Create the following PL/SQL script: -- ch07_1a.sql, version 1.0 SET SERVEROUTPUT ON; DECLARE v_num NUMBER := &sv_num; BEGIN DBMS_OUTPUT.PUT_LINE ('Square root of 'v_num ' is 'SQRT(v_num)); EXCEPTION WHEN VALUE_ERROR THEN DBMS_OUTPUT.PUT_LINE ('An error has occurred'); END; In the preceding script, the exception VALUE_ERROR, is raised when conversion or type mismatch errors occur. This exception is covered in greater detail in Lab 7.2 of this chapter. In order to test this script fully, execute it two times. For the first run, enter a value of 4 for the variable v_num . For the second run, enter the value of -4 for the variable v_num . Execute the script, and then answer the following questions:
|