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

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

PHPz
Release: 2023-08-29 09:05:02
forward
1427 people have browsed it

在 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
Copy after login

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
Copy after login

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
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template