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

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

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

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

Benjamin Rosenzweig

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

فونت

اندازه قلم

+ - پیش فرض

حالت نمایش

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



Lab 5.3 Exercises


5.3.1 Use Nested IF Statements


In this exercise, you will use nested IF statements. This script will convert the value of a temperature from one system to another. If the temperature is supplied in Fahrenheit, it will be converted to Celsius, and vice versa.

Create the following PL/SQL script:

-- ch05_4a.sql, version 1.0
SET SERVEROUTPUT ON
DECLARE
v_temp_in NUMBER := &sv_temp_in;
v_scale_in CHAR := '&sv_scale_in';
v_temp_out NUMBER;
v_scale_out CHAR;
BEGIN
IF v_scale_in != 'C' AND v_scale_in != 'F' THEN
DBMS_OUTPUT.PUT_LINE ('This is not a valid scale');
ELSE
IF v_scale_in = 'C' THEN
v_temp_out := ( (9 * v_temp_in) / 5 ) + 32;
v_scale_out := 'F';
ELSE
v_temp_out := ( (v_temp_in 32) * 5 ) / 9;
v_scale_out := 'C';
END IF;
DBMS_OUTPUT.PUT_LINE ('New scale is: '||
v_scale_out);
DBMS_OUTPUT.PUT_LINE ('New temperature is: '||
v_temp_out);
END IF;
END;

Execute the script, and then answer the following questions:

a)

What output is printed on the screen if the value of 100 is entered for the temperature, and the letter "C" is entered for the scale?

b)

Try to run this script without providing a value for the temperature. What message will be displayed on the screen? Why?

c)

Try to run this script providing an invalid letter for the temperature scale, for example, letter "V." What message will be displayed on the screen? Why?

d)

Rewrite this script so that if an invalid letter is entered for the scale, v_temp_out is initialized to zero and v_scale_out is initialized to C.


    / 289