codemaniacstudio

Write a program to enter temperature in Fahrenheit and convert to Celsius in PLSQL block.

Practical Practice 9

Oracle Practice

Write a program to enter temperature in Fahrenheit and convert to Celsius in PLSQL block.

Write a program to enter temperature in Fahrenheit and convert to Celsius in PLSQL block.

SOLUTION

--Static code

SET SERVEROUTPUT ON;
DECLARE
    fahrenheit NUMBER := 77; 
    celsius NUMBER;    
BEGIN
    
    celsius := (fahrenheit - 32) * 5/9;
    DBMS_OUTPUT.PUT_LINE('Temperature in Fahrenheit: ' || fahrenheit || '°F');
    DBMS_OUTPUT.PUT_LINE('Temperature in Celsius: ' || celsius || '°C');
END;
/
    


--Dynamic code
SET SERVEROUTPUT ON;
DECLARE
    fahrenheit NUMBER; 
    celsius NUMBER;    
BEGIN
    
    fahrenheit := &fahrenheit;
    celsius := (fahrenheit - 32) * 5/9;
    DBMS_OUTPUT.PUT_LINE('Temperature in Fahrenheit: ' || fahrenheit || '°F');
    DBMS_OUTPUT.PUT_LINE('Temperature in Celsius: ' || celsius || '°C');
END;
/

TRY IT YOURSELF

Exit mobile version