在 PL/SQL 中将距离从公里转换为米和厘米
先决条件——PL/SQL介绍
在 PL/SQL 代码中,命令组被安排在一个块中。块组相关的声明或语句。在声明部分,我们声明变量,在开始和结束部分之间,我们执行操作。
以公里为单位的给定距离,任务是将其转换为米和厘米。
例子:
Input: KM = 10
Output: 10 KM is equivalent to 10000 meters
10 KM is equivalent to 1000000 centimeters
Input: KM = 2.5
Output: 2.5 KM is equivalent to 2500 meters
2.5 KM is equivalent to 250000 centimeters
方法是将KM数据乘以1000换算成米,乘以100000换算成厘米。
以下是所需的实现:
SQL
--DECLARATION SECTION
DECLARE
--VARIABLE DECLARATION -KM, MET, CEM;
km NUMBER := 6.9;
met NUMBER := 0;
cem NUMBER := 0;
--CODE BLOCK
BEGIN
--CALCULATE METERS
met := km * 1000;
--CALCULATE CENTIMETERS
cem := met * 100;
--DISPLAY RESULT
dbms_output.Put_line('6.9KM is equivalent to meters: ' ||met);
dbms_output.Put_line('6.9KM is equivalent to centimeters:' ||cem);
END;
--END PROGRAM
输出 :
6.9KM is equivalent to meters: 6900
6.9KM is equivalent to centimeters:690000