SQL>
SQL>
SQL> CREATE OR REPLACE PACKAGE temperature IS
2 PROCEDURE Temperature_Conversion ( degree number,cf varchar2);
3 FUNCTION Celsius_to_Fahrenheit ( degree NUMBER) Return Number;
4 FUNCTION Fahrenheit_to_Celsius ( degree NUMBER) Return Number;
5 END temperature;
6 /
Package created.
SQL>
SQL> CREATE OR REPLACE PACKAGE BODY temperature AS
2
3 PROCEDURE temperature_conversion (degree number,cf varchar2) IS
4 buffer NUMBER := 0;
5 BEGIN
6 IF cf = 'C'
7 THEN
8 buffer := TEMPERATURE.Celsius_to_Fahrenheit(degree);
9 DBMS_OUTPUT.PUT_LINE('Fahrenheit = ' || buffer);
10 RETURN;
11 ELSIF cf = 'F'
12 THEN
13 buffer := TEMPERATURE.Fahrenheit_to_Celsius(degree);
14 DBMS_OUTPUT.PUT_LINE('Celsius = ' || buffer);
15 RETURN;
16 END IF;
17 DBMS_OUTPUT.PUT_LINE('Bad Temperature Conversion Code: ' || cf);
18 RETURN;
19
20 END temperature_conversion;
21
22 FUNCTION celsius_to_fahrenheit (degree NUMBER)
23 RETURN NUMBER IS
24 buffer NUMBER;
25
26 BEGIN
27 buffer := (degree * 9/5) + 32;
28 RETURN buffer;
29 END celsius_to_fahrenheit;
30
31 FUNCTION fahrenheit_to_celsius (degree NUMBER)
32 RETURN NUMBER IS
33 buffer NUMBER;
34
35 BEGIN
36 buffer := (5/9) * (degree - 32);
37 RETURN buffer;
38 END fahrenheit_to_celsius;
39
40 END temperature;
41 /
Package body created.
SQL>
SQL>
|