SQLCODE -204: Undefined object name
SQLCODE -204 (SQLSTATE 42704) means the SQL names a table, view, alias or other object that doesn't exist in this Db2 subsystem under the name Db2 worked out. A wrong schema qualifier is the usual reason.
Other names for this code
Also written as SQL -204, SQLCODE=-204, SQLCODE = -204, db2 -204, sqlstate 42704, SQL0204N, is an undefined name.
What it means
Every table, view, alias and sequence in Db2 has a two-part name, a schema and an object name, such as PAYPROD.
If no object exists with the resulting full name, Db2 returns -204 and puts the name it looked for in SQLERRMC. Compare that name with the one you expected.
Static SQL can get -204 at bind time or at run time. With VALIDATE(BIND), the bind fails and no new package is made. With VALIDATE(RUN), the bind ends with warnings and Db2 checks the name again each time the statement runs.
Common causes
- The package was bound with a QUALIFIER or owner from another environment. EMP_
HIST resolves to PAYTEST.EMP_ HIST in production, or the other way round. - The table, view or alias was never created in this subsystem, or it was dropped for a change and not yet recreated.
- The object name is misspelled in the program.
- A dynamic SQL user, for example in SPUFI or QMF, has a different CURRENT SQLID or CURRENT SCHEMA from the one the query was written for.
- An alias still exists but the table behind it was dropped. Db2 keeps the alias, and using it gives -204 for the missing table.
- A NEXT VALUE FOR expression names a sequence that isn't in that schema.
How to find the problem
- Read the name in the DSNT408I message or SQLERRMC. It is fully qualified, so you can see which schema Db2 used.
- Look the object up with
SELECT CREATOR, NAME, TYPE FROM SYSIBM.SYSTABLES WHERE NAME = 'EMP_. TYPE shows a table (T), view (V) or alias (A), and CREATOR shows which schemas have one.HIST' - For static SQL, check QUALIFIER and OWNER for the package in SYSIBM.
SYSPACKAGE. - For dynamic SQL, run
SELECT CURRENT SQLID, CURRENT SCHEMA FROM SYSIBM.SYSDUMMY1in the same session. - Look at the bind job output. A VALIDATE(RUN) bind lists a warning for the same name, which tells you the problem was there before the program ran.
How to fix it
- Rebind the package with the right qualifier for this environment, for example
REBIND PACKAGE(PAYCOLL..PAYUPD1) QUALIFIER(PAYPROD) - For dynamic SQL, issue
SET CURRENT SCHEMA = 'PAYPROD'before the query, or qualify the name in the statement. - Create the missing object if the name is right, or create an alias that points to the right table.
- Fix a misspelled name in the program, then precompile, compile and bind again.
- If a bind failed with -204, no new package was made. Bind again after the fix, or the new load module will get -805 at run time.
What it looks like
PAYUPD1 - OPEN CSR-HIST FAILED DSNT408I SQLCODE = -204, ERROR: PAYTEST.EMP_HIST IS AN UNDEFINED NAME DSNT418I SQLSTATE = 42704 SQLSTATE RETURN CODE
IBM documentation
IBM documentation: -204. Use the documentation for your installed release.
Related codes
Questions
Why does the query work in SPUFI but fail in the program?
SPUFI runs dynamic SQL under your CURRENT SQLID or CURRENT SCHEMA. The program's static SQL uses the QUALIFIER it was bound with. If they differ, the same unqualified name points at different tables.
Is -204 the same as a missing column?
No. A missing column gives -206. -204 means the whole object, such as the table or view, couldn't be found.
Does Db2 for LUW use the same code?
Yes. SQL0204N with SQLSTATE 42704 means the same thing there.