Home  >  Article  >  Database  >  Convert distance from kilometers to meters and centimeters in PL/SQL

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

PHPz
PHPzforward
2023-08-29 09:05:021350browse

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

Example

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

The method we will use

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

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

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!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete