Prentice Hall Oracle Plsql By Example 3Rd Edition [Electronic resources] نسخه متنی

اینجــــا یک کتابخانه دیجیتالی است

با بیش از 100000 منبع الکترونیکی رایگان به زبان فارسی ، عربی و انگلیسی

Prentice Hall Oracle Plsql By Example 3Rd Edition [Electronic resources] - نسخه متنی

Benjamin Rosenzweig

| نمايش فراداده ، افزودن یک نقد و بررسی
افزودن به کتابخانه شخصی
ارسال به دوستان
جستجو در متن کتاب
بیشتر
تنظیمات قلم

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

روز نیمروز شب
جستجو در لغت نامه
بیشتر
لیست موضوعات
توضیحات
افزودن یادداشت جدید



Lab 7.1 Exercises


7.1.1 Understanding the Importance of Error Handling


In 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:

a)

What output was printed on the screen (for both runs)?

b)

Why do you think an error message was generated when the script was run a second time?

c)

Assume that you are not familiar with the exception VALUE_ERROR. How would you change this script to avoid this runtime error?


    / 289