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

Leave a Reply

Your email address will not be published. Required fields are marked *

sign up!

We’ll send you the hottest deals straight to your inbox so you’re always in on the best-kept software secrets.