Convert distance from km to meters and centimeters in PL/SQL

PL/SQLMySQLDatabase

The task is to convert the distance from kilometers to meters and centimeters in PL/SQL.PL/SQL is the extension of SQL which combines the Data manipulation of SQL with the working of procedural language.

According to the problem we should have distance in kilometers whose value we have to convert in meters and centimeters.

As per the conversion rule −

1km = 1000 meters

1km = 100000 centimeters

According to this conversion rule we want the distance to be converted by a logic in PL/SQL.

Example

Input: kilometer = 10
Output: meter = 10000
   Centimeter = 1000000
Input: kilometer = 9
Output: meter = 9000
   Centimeter = 900000

Approach we will be using

  • Take the value of the kilometers as an input.

  • Multiply the value of kilometers by 1000 then store and print the result in meters.

  • Multiply the value of meters by 100 then store and print the result in centimeters.

Example

--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

Output

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
raja
Published on 15-May-2020 11:56:34
Advertisements