Domanda

Here's a code I wrote for Oracle PL/SQL Armstrong Number

declare
num number;
sum number;
temp number;
val number;
begin
num:=#
temp:=num;
while temp<>0 loop
val:=trunc(temp mod 10);
sum:=sum +(val*val*val);
temp:=temp/10;
end loop;
if sum=num then
dbms_output.put_line('number is Armstrong');
else
dbms_output.put_line('number is not Armstrong');
end if;
end;

I get the following error:

ERROR at line 11: ORA-06550: line 11, column 10: PLS-00103: Encountered the symbol "+" when expecting one of the following: ( The symbol "(" was substituted for "+" to continue. ORA-06550: line 11, column 24: PLS-00103: Encountered the symbol ";" when expecting one of the following: ) * & - + / at mod remainder rem || year day The symbol ")" was substituted for ";" to continue. ORA-06550: line 14, column 7: PLS-00103: Encountered the symbol "=" when expecting one of the following: (

What have I done wrong? Thanks.

È stato utile?

Soluzione

sum is a reserved word in most databases (including Oracle). It's an aggregate function, which is why Oracle's telling you that it's expecting a left parenthesis. Change the name of that variable and the block will work.

Autorizzato sotto: CC-BY-SA insieme a attribuzione
Non affiliato a StackOverflow
scroll top