2

I use while loop to calculate the integers from 1 to 10 in Pl Sql.

This is the code:

set serveroutput on;
declare
i number := 0;
sum number := 0;
begin
while i <= 10 loop
sum := sum + i ;
i := i + 1;
end loop;
dbms_output.put_line ( sum );
end;
/

what is the problem here?

This is the error message:

sum := sum + i ;
           *
ERROR at line 6: 
ORA-06550: line 6, column 12: 
PLS-00103: Encountered the symbol "+" when expecting one of the following: 
( 
ORA-06550: line 9, column 28: 
PLS-00103: Encountered the symbol ")" when expecting one of the following: 
(
2
  • 1
    Please add what is wrong, what you are expecting. Any error message? Commented Dec 25, 2015 at 13:38
  • oh this is the error message sum := sum + i ; * ERROR at line 6: ORA-06550: line 6, column 12: PLS-00103: Encountered the symbol "+" when expecting one of the following: ( ORA-06550: line 9, column 28: PLS-00103: Encountered the symbol ")" when expecting one of the following: ( Commented Dec 25, 2015 at 13:42

1 Answer 1

5

Try not using the variable name sum.

i.e

set serveroutput on;
declare
i number := 0;
s number := 0;
begin
while i <= 10 loop
s := s + i ;
i := i + 1;
end loop;
dbms_output.put_line ( s );
end;
/

Seems to work

Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.