oracle - pl/sql中数字的阶乘

标签 oracle plsql syntax-error

下面的pl/sql程序在执行sum sum == temp * sum;时会生成错误。遇到符号;期待时(。请解释我的错误。

declare
  n number;
  temp number;
  sum number := 1;
begin
  n := &n;
  temp := n;
  while temp>0 loop
    sum := temp*sum;
    temp := temp-1;
  end loop;
  dbms_output.put_line('Factorial of '||n||' is '||sum);
end;
/

最佳答案

Sum是sql中的保留字。像这样更改变量名称

declare
  n number;
  temp number;
  sum_ number := 1;
begin
  n := &n;
  temp := n;
  while temp>0 loop
    sum_ := temp*sum_;
    temp := temp-1;
  end loop;
  dbms_output.put_line('Factorial of '||n||' is '||sum_);
end;
/

关于oracle - pl/sql中数字的阶乘,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/22372570/

相关文章:

java - 无法从连接池获取/创建连接

python - SQLAlchemy - 获取表的创建日期

oracle - 创建 Oracle 过程

sql - 顶点 : Submit without refreshing the page

python-3.x - Python错误,我做得完全正确,但出现错误

python - 语法错误 : invalid syntax Python 2. 7

java - 如何在Oracle中压缩XML(CLOB数据)?

sql - 如何创建一个约束来确保输入的日期总是 >= 今天或 future 的日期?

oracle - PL/SQL Oracle错误处理

javascript - 按照教程,无法找出我的 javascript 语法错误