codemaniacstudio

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

Practical Practice 8

Oracle Practice

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

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

SOLUTION

--Static code

set serveroutput on;
DECLARE
    celsius NUMBER := 25;    
    fahrenheit NUMBER; 
BEGIN
    -- Conversion formula: Fahrenheit = (Celsius * 9/5) + 32
    fahrenheit := (celsius * 9/5) + 32;
    -- Display the converted Fahrenheit temperature
    DBMS_OUTPUT.PUT_LINE('Temperature in Celsius: ' || celsius || '°C');
    DBMS_OUTPUT.PUT_LINE('Temperature in Fahrenheit: ' || fahrenheit || '°F');
END;
/
    


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

TRY IT YOURSELF

Exit mobile version