Home >Database >Mysql Tutorial >Convert distance from kilometers to meters and centimeters in PL/SQL
Task is to convert distance from kilometers to meters and centimeters in PL/SQL. PL/SQL is an extension of SQL that combines the data manipulation of SQL with the work of a procedural language.
According to this question we should have the distance in kilometers and we have to convert its value Convert in meters and centimeters.
According to the conversion rule-
1km = 1000 meters
1km = 100000 centimeters
According to this conversion rule we hope to use the logic in PL/SQL to conversion distance.
Input: kilometer = 10 Output: meter = 10000 Centimeter = 1000000 Input: kilometer = 9 Output: meter = 9000 Centimeter = 900000
takes the kilometer value as input.
Multiply the kilometers value by 1000, then store and print the result in meters.
Multiply the meter value by 100, then store and print the result in centimeters.
--DECLARATION DECLARE KM NUMBER := 4.5; meter NUMBER := 0; Cem NUMBER := 0; --BODY BEGIN meter := km * 1000; Cem := meter * 100; dbms_output.Put_line('The value of 4.5 KM to meters is: ' ||meter); dbms_output.Put_line('The value of 4.5 KM to centimeters is: ' ||cem); END; --BODY END
If we run the above code, it will generate the following output -
The value of 4.5 KM to meters is: 4500 The value of 4.5 KM to centimeters is: 450000
The above is the detailed content of Convert distance from kilometers to meters and centimeters in PL/SQL. For more information, please follow other related articles on the PHP Chinese website!