Please be aware that the content in SAP SQL Anywhere Forum will be migrated to the SAP Community in June and this forum will be retired.

Can somebody tell me which mistake am I doing, why I get syntax error with this block?

create or replace procedure myproc()
begin
declare myvar int;
set myvar = 1;
while myvar <10 begin
set myvar= myvar+1;
end;
end;

asked 22 Jun '23, 08:08

Baron's gravatar image

Baron
2.1k135148177
accept rate: 48%

as alternative this has worked:

create or replace procedure myproc()
begin
declare myvar int;
set myvar = 1;
myloop:
while myvar <10 loop
set myvar= myvar+1;
end loop myloop;
end;
(22 Jun '23, 08:13) Baron
2

The correct syntax for WHILE is

WHILE...LOOP END LOOP;

The loop name is optional. See LOOP in the documentation for a complete discussion.

(22 Jun '23, 08:20) Chris Keating

You are mixing your Watcom SQL and Transact-SQL into the same procedure. The brackets after the procedure name and the BEGIN..END after the procedure definition is Watcom-SQL, but you're trying to use the Transact-SQL version of the WHILE statement (i.e. no LOOP..END LOOP).

You alternative SQL for the procedure is all Watcom-SQL.

permanent link

answered 22 Jun '23, 08:40

Reg%20Domaratzki's gravatar image

Reg Domaratzki
7.7k343118
accept rate: 37%

edited 22 Jun '23, 08:54

Your answer
toggle preview

Follow this question

By Email:

Once you sign in you will be able to subscribe for any updates here

By RSS:

Answers

Answers and Comments

Markdown Basics

  • *italic* or _italic_
  • **bold** or __bold__
  • link:[text](http://url.com/ "title")
  • image?![alt text](/path/img.jpg "title")
  • numbered list: 1. Foo 2. Bar
  • to add a line break simply add two spaces to where you would like the new line to be.
  • basic HTML tags are also supported

Question tags:

×19

question asked: 22 Jun '23, 08:08

question was seen: 263 times

last updated: 22 Jun '23, 08:54