Practical Practice 7

Oracle Practice
Write a program to enter length in centimeter and convert it into meter and kilometer in PLSQL block.
Write a program to enter length in centimeter and convert it into meter and kilometer in PLSQL block.
SOLUTION
--Static code
set serveroutput on;
DECLARE
length_cm NUMBER := 15;
length_m NUMBER ;
length_km NUMBER ;
BEGIN
length_cm := 1500;
length_m := length_cm / 100; -- 1 meter = 100 centimeters
length_km := length_cm / 100000; -- 1 kilometer = 100,000 centimeters
-- Output the results
DBMS_OUTPUT.PUT_LINE('Length in Centimeters: ' || length_cm || ' cm');
DBMS_OUTPUT.PUT_LINE('Length in Meters: ' || length_m || ' m');
DBMS_OUTPUT.PUT_LINE('Length in Kilometers: ' || length_km || ' km');
END;
/

--Dynamic code
set serveroutput on;
DECLARE
length_cm NUMBER := &length_cm;
length_m NUMBER ;
length_km NUMBER ;
BEGIN
length_m := length_cm / 100; -- 1 meter = 100 centimeters
length_km := length_cm / 100000; -- 1 kilometer = 100,000 centimeters
-- Output the results
DBMS_OUTPUT.PUT_LINE('Length in Centimeters: ' || length_cm || ' cm');
DBMS_OUTPUT.PUT_LINE('Length in Meters: ' || length_m || ' m');
DBMS_OUTPUT.PUT_LINE('Length in Kilometers: ' || length_km || ' km');
END;
/

--Dynamic code set serveroutput on; DECLARE length_cm NUMBER := &length_cm; length_m NUMBER ; length_km NUMBER ; BEGIN length_m := length_cm / 100; -- 1 meter = 100 centimeters length_km := length_cm / 100000; -- 1 kilometer = 100,000 centimeters -- Output the results DBMS_OUTPUT.PUT_LINE('Length in Centimeters: ' || length_cm || ' cm'); DBMS_OUTPUT.PUT_LINE('Length in Meters: ' || length_m || ' m'); DBMS_OUTPUT.PUT_LINE('Length in Kilometers: ' || length_km || ' km'); END; /