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:
[ ... ]$ cat aa.sql
CREATE TABLE TEMP_ITERATIONS ( X VARCHAR(50) ) @
BEGIN ATOMIC
DECLARE i INT DEFAULT 12;
WHILE i > 0 DO
INSERT INTO TEMP_ITERATIONS VALUES ('IT'|| RTRIM(CHAR(i)));
SET i = i - 1;
END WHILE;
END @
[ ... ]$ db2 -td@ -f aa.sql
DB20000I The SQL command completed successfully.
DB20000I The SQL command completed successfully.
[ ... ]$ db2 "select * from TEMP_ITERATIONS"
X
--------------------------------------------------
IT12
IT11
IT10
[...]
12 record(s) selected.
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:
[ ... ]$ cat aa.sql
CREATE TABLE TEMP_ITERATIONS ( X VARCHAR(50) ) ;
BEGIN ATOMIC
DECLARE i INT DEFAULT 12; --
WHILE i > 0 DO
INSERT INTO TEMP_ITERATIONS VALUES ('IT'|| RTRIM(CHAR(i))); --
SET i = i - 1; --
END WHILE; --
END ;
[ ... ] db2 -tf aa.sql
DB20000I The SQL command completed successfully.
DB20000I The SQL command completed successfully.
[ ... ]$ db2 "select * from TEMP_ITERATIONS"
X
--------------------------------------------------
IT12
IT11
IT10
[...]
12 record(s) selected.
i INT
but then decrementCOUNT
in the loop -- not sure I understand the logic here. TheVALUES
clause in theINSERT
requires parentheses. I suggest you review syntax diagrams in the manual. – mustaccio