5.3.1 Use Nested IF StatementsIn 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:
|