用oracle编写求1的阶乘到10的阶乘的和
时间: 2023-09-01 13:08:20 浏览: 140
阶乘求和1到10
以下是使用Oracle SQL编写的求1的阶乘到10的阶乘的和的语句:
```
WITH nums AS (
SELECT LEVEL AS num
FROM DUAL
CONNECT BY LEVEL <= 10
)
SELECT SUM(
CASE WHEN num = 1 THEN 1
WHEN num = 2 THEN 2
WHEN num = 3 THEN 6
WHEN num = 4 THEN 24
WHEN num = 5 THEN 120
WHEN num = 6 THEN 720
WHEN num = 7 THEN 5040
WHEN num = 8 THEN 40320
WHEN num = 9 THEN 362880
WHEN num = 10 THEN 3628800
END
) AS factorial_sum
FROM nums;
```
注:以上语句利用Oracle的`LEVEL`和`CONNECT BY`语句生成从1到10的数字序列,并使用`CASE`语句计算每个数字的阶乘,最后求和得到结果。
阅读全文