先决条件 – PL/SQL简介 在PL/SQL代码中,命令组排列在一个块中。与声明或语句相关的块组。 我们在部分中声明变量,在部分中声明变量,在部分中执行变量。
null
这里,首先,我们取三个变量num、fact和temp,并在num variable中赋值(即我们想要哪个数字阶乘)。 然后我们把事实变量赋值给1。
例如:
Input : 4 Output : 24
Input : 6 Output : 720
以下是所需的实施:
declare -- declare variable num , fact -- and temp of datatype number num number := 6; fact number := 1; temp number; begin temp :=num; -- here we check condition -- with the help of while loop while( temp >0 ) loop fact := fact* temp ; temp := temp -1; end loop; dbms_output.put_line( 'factorial of ' || num || ' is ' || fact); end ; -- Program End |
输出:
factorial of 6 is 720.
© 版权声明
文章版权归作者所有,未经允许请勿转载。
THE END