I am migrating from MS SQL Server to IBM DB2 (Version 9.7). Trying to write a compound SQL While Loop with local variables (Not a part of Stored Procedure), something like -
BEGIN ATOMIC
DECLARE i INT DEFAULT 12;
WHILE i > 0
"DO ....";
SET COUNT = COUNT - 1;
END WHILE;
END
But I get an error just in first line for declaring variables-
SQL0104N An unexpected token "12" was found following "ECLARE I INT DEFAULT". Expected tokens may include: "END-OF-STATEMENT"
Any help is greatly appreciated.
I assume that your problem has to do with statement terminator (easier to see if you provide the actual errors you get). I tested the following and it worked:
Here I used @ as a statement terminator since ; has a special meaning. If you don't want to change the statement terminator a trick is to "hide" the ; inside the compound statement by adding a comment at the end of the line: