'how to solve db2 code: -104, SQL State: 42601
--/
BEGIN
FOR V AS MYCURSOR CURSOR FOR SELECT ID,NAME,AGE FROM PEOPLE
DO
BEGIN
INSERT INTO PERSON(NAME,AGE) VALUES(V.NAME,V.AGE);
END;
END FOR;
END;
/
DB tool is Dbvisualizer 10.0.1, so I need "--/" and "/"
Message: [Code: -104, SQL State: 42601] An unexpected token "V" was found following "BEGIN FOR ". Expected tokens may include: "JOIN".. SQLCODE=-104, SQLSTATE=42601, DRIVER=4.22.29 Help plz.
Solution 1:[1]
In your query tool, set the statement terminator to something that is not ';'.
E.g. use @
BEGIN
FOR V AS MYCURSOR CURSOR FOR SELECT ID,NAME,AGE FROM PEOPLE
DO
BEGIN
INSERT INTO PERSON(NAME,AGE) VALUES(V.NAME,V.AGE);
END;
END FOR;
END
@
Solution 2:[2]
You must use different Statement Delimiter / Terminator to run compound statements. Every client tool has its own methods of setting it. Dbvisualizer:
Tools\Tool Properties\SQL Commander\Statement Delimiters:
SQL Statement Delimiter:
SQL Statement Delimiter 1: @
SQL Statement Delimiter 2: @
Using the DBMS Output Tab:
Only in DbVisualizer DbVisualizer Pro edition. This feature is only available in the DbVisualizer Pro edition.
BEGIN FOR V AS MYCURSOR CURSOR FOR SELECT ID,NAME,AGE FROM PEOPLE DO BEGIN INSERT INTO PERSON(NAME,AGE) VALUES(V.NAME,V.AGE); END; END FOR; END @
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
Solution | Source |
---|---|
Solution 1 | Paul Vernon |
Solution 2 | Jit Sarkar |