# SQLCODE -104: Illegal symbol in the statement

Source: https://wndsoftware.com/mainframe-errors/sqlcode-104

### SQLCODE -104: Illegal symbol in the statement

SQLCODE -104 (SQLSTATE 42601) is a syntax error. Db2 found a word or symbol, shown as the token in the message, at a point where the SQL grammar doesn't allow it, and it lists some symbols that could have gone there instead.


#### Other names for this code

Also written as `SQL -104`, `SQLCODE=-104`, `SQLCODE = -104`, `db2 -104`, `sqlstate 42601`, `SQL0104N`, `SQL0104`, `illegal symbol`, `SQLCODE=-104, SQLSTATE=42601`.


### What it means

Db2 reads a statement from left to right and checks each token against the SQL grammar. When it meets one that can't follow what came before, it stops and returns -104. SQLERRMC holds that token and a short list of tokens that would have been acceptable at that point.

Take both with care. The token is where Db2 noticed the problem, not always where the mistake is. A missing comma, an extra comma or an unclosed parenthesis earlier in the statement often shows up as an error on a perfectly good word later on. The list of legal symbols assumes everything before the token is correct, and IBM says some of the listed symbols may not even be valid in Db2 for z/OS. Use it as a hint about what Db2 expected, not as a fix.

If the token is the end of the statement, Db2 ran out of text before the statement was complete. That points to a missing clause, an unclosed parenthesis, or SQL that was cut off. IBM also uses -104 for one specific case, a RELEASE TO SAVEPOINT statement with no savepoint name.


### Common causes

- A missing or extra comma, such as a comma after the last column just before FROM.
- Parentheses that don't balance, often in nested subqueries or CASE expressions.
- A misspelled keyword, or clauses in the wrong order, such as ORDER BY before WHERE.
- Syntax from another database product that Db2 for z/OS doesn't accept, such as SELECT TOP 10.
- A semicolon or other terminator left at the end of a statement sent through JDBC, ODBC or PREPARE.
- SQL text that was cut short. Text in columns 73 to 80 of a numbered 80-byte record can be dropped as a sequence number, and a buffer length that's too small has the same effect.


### How to find the problem

- Read the token in the `DSNT408I` message or in SQLERRMC, then look at the text just before it in the statement.
- Check the list of legal symbols. If it contains a comma or a closing parenthesis, something earlier in the statement probably needs one.
- For SQL from a program or tool, print the exact text Db2 received. What was sent can differ from what you wrote.
- In SPUFI, check the SQL terminator on the defaults panel and make sure nothing past column 72 is being lost.
- In a Java stack trace, the same information appears as `SQLCODE=-104, SQLSTATE=42601, SQLERRMC=` followed by the token and the list.


### How to fix it

- Fix the syntax near the token, working backwards if the token itself looks right.
- Rewrite syntax from other products in Db2 for z/OS form, for example FETCH FIRST 10 ROWS ONLY instead of TOP 10.
- Remove trailing semicolons from statements passed to JDBC, ODBC or PREPARE.
- Keep SQL inside columns 1 to 72, or turn numbering off in ISPF with `NUMBER OFF` or `UNNUM`.
- Test the statement in SPUFI or another query tool before you put it in a program, so syntax errors show up early.


### IBM documentation

[IBM documentation: -104](https://www.ibm.com/docs/en/db2-for-zos/13.0.0?topic=codes-104). Use the documentation for your installed release.

[Report a correction to WND Software](https://wndsoftware.com/contact#message).

Technical reviewer: [Albert Joseph](https://wndsoftware.com/authors/albert-joseph), WND Software.

Last reviewed 2026-10-18 by the WND Software team. Written in our own words. For the full reference, check IBM’s Db2 for z/OS documentation for your release.


### Related codes

[SQLCODE -199 Illegal use of a keyword Read →](https://wndsoftware.com/mainframe-errors/sqlcode-199)
[SQLCODE -007 Illegal character in the statement Read →](https://wndsoftware.com/mainframe-errors/sqlcode-7)
[SQLCODE -010 String constant not terminated Read →](https://wndsoftware.com/mainframe-errors/sqlcode-10)
[SQLCODE -206 Column name not valid Read →](https://wndsoftware.com/mainframe-errors/sqlcode-206)
[SQLCODE -084 Unacceptable SQL statement Read →](https://wndsoftware.com/mainframe-errors/sqlcode-84)

### Questions


#### Why does -104 point at a word that looks correct?

Because Db2 reports where it noticed the problem. The real mistake, often a missing comma or parenthesis, is usually a little earlier in the statement.


#### Can I trust the list of symbols that might be legal?

Only as a hint. It assumes the text before the token is correct, and IBM notes that some listed symbols may not be valid in Db2 for z/OS.


#### Is it the same on Db2 for LUW and Db2 for i?

Yes, with different wording. Db2 for LUW reports SQL0104N, 'An unexpected token was found', and Db2 for i reports SQL0104, 'Token was not valid'. All use SQLSTATE 42601.

[Db2 SQLCODEs](https://wndsoftware.com/mainframe-errors/db2-sqlcodes) · [SQLCODE -101](https://wndsoftware.com/mainframe-errors/sqlcode-101) · [SQLCODE -117](https://wndsoftware.com/mainframe-errors/sqlcode-117)

[← All error codes](https://wndsoftware.com/mainframe-errors/)
