SQLCODE -199: Illegal use of a keyword
SQLCODE -199 (SQLSTATE 42601) is a syntax error. Db2 found an SQL keyword where the grammar doesn't allow one, and the message lists tokens it expected at that point instead.
Other names for this code
Also written as SQL -199, SQLCODE=-199, SQLCODE = -199, db2 -199, sqlstate 42601, SQL0199N, illegal use of keyword.
What it means
-199 is a close relative of -104. Both mean the statement breaks the SQL grammar, and both use SQLSTATE 42601. With -199 the word that stopped Db2 is a keyword, such as FROM, WHERE, ORDER or AND. The keyword is fine on its own, but it can't appear where it is. The message names it and gives a list of tokens that would have been acceptable.
As with -104, the mistake is often just before the keyword. A missing operand, a missing comma or a clause in the wrong order makes the next keyword look out of place.
Reserved words cause a second kind of -199. If a table or column has a name that is also an SQL keyword, using it without double quotes can make Db2 read it as the keyword.
Common causes
- Clauses in the wrong order, such as ORDER BY before WHERE or GROUP BY after ORDER BY.
- A missing operand before a keyword, as in
WHERE STATUS = AND DEPT = 'A00'. - A keyword repeated or left over after an edit, such as
WHERE WHEREor a trailing AND. - A name that is also an SQL reserved word, used without double quotes.
- Syntax from another database product, where a keyword is valid in a position Db2 for z/OS doesn't support.
How to find the problem
- Read the keyword and the expected tokens in the
DSNT408Imessage or SQLERRMC. - Look at the text just before the keyword. Check that the previous clause is complete and the clauses are in the right order.
- If the keyword is really a table or column name, check the list of reserved words in the SQL Reference for your release.
- For SQL built by a program, print the exact text Db2 received. Generated SQL often leaves a dangling AND or comma when a condition is empty.
How to fix it
- Put the clauses in the order Db2 expects, and complete any expression that is missing an operand.
- Remove duplicated or leftover keywords. In programs that build SQL, add AND or a comma only between conditions, never after the last one.
- Put names that are reserved words in double quotes, in uppercase, or better, rename the object.
- Rewrite syntax from other products in Db2 for z/OS form.
IBM documentation
IBM documentation: -199. Use the documentation for your installed release.
Related codes
Questions
What's the difference between -199 and -104?
Both are syntax errors with SQLSTATE 42601. -199 names a keyword that is out of place. -104 is the general syntax error, and its token can be any symbol, a keyword included.
Can a column name cause -199?
Yes, if the name is also a reserved word and isn't in double quotes. Db2 reads it as the keyword and the statement no longer parses.
Is it the same on Db2 for LUW?
SQL0199N has the same SQLSTATE, 42601. The LUW message says the use of a reserved word is not valid and shows the text before it.