这个PL / SQL程序有什么问题?

时间:2016-06-09 06:22:40

标签: sql oracle plsql

declare
    p number:=371;
    x number;
    t number;
    sum number;
begin
    x:=p;
    while x>0 loop
        t:=x mod 10;
        sum:=sum+ t**3;
        x:=x/10;
    end loop;

    if (sum=p) then
        dbms_output.put_line(p||+' '||'an armstrong number');
    end if;
end;
/

2 个答案:

答案 0 :(得分:0)

sum是关键字,只需为您的变量使用其他名称,例如mysum

declare
    p number:=371;
    x number;
    t number;
    mysum number;
begin
    x:=p;
    while x>0 loop
        t:=x mod 10;
        mysum:=mysum + t**3;
        x:=x/10;
    end loop;

    if (mysum=p) then
        dbms_output.put_line(p||+' '||'an armstrong number');
    end if;
end;
/

答案 1 :(得分:0)

您不能将关键字用作变量名称。 sum是oracle中的关键字,因此将变量名称从sum更改为其他任何内容。

相关问题