Db2 Troubleshooting
SQLCODE -305 null indicator missing
SQLCODE -305: null indicator missing — the column can be null but the program gave no indicator variable.
What it means
- After every EXEC SQL, DB2 returns a SQLCODE: 0 means success, +100 means no row found, and negative values mean an error.
Common causes
- SELECT/UPDATE on a nullable column without an indicator.
- FETCH into a host variable with no indicator.
How to diagnose
- Check the column definition: is it nullable?
- Look at the INTO list for missing indicators.
How to fix it
- Add an indicator variable: EXEC SQL FETCH ... INTO :HV:IND.
- Or change the column to NOT NULL if business rules allow.
Example: Add the indicator variable
EXEC SQL SELECT SALARY INTO :WS-SAL :WS-SAL-IND
FROM EMP WHERE ID = :WS-ID END-EXEC.
IF WS-SAL-IND < 0
*> column was null
END-IF.
Indicator < 0 means the value is null.
Interview tip
- Q: How would you troubleshoot a SQLCODE -305 null indicator missing in production?
- A: I would check the SQLCODE and SQLERRM immediately after the failing statement, reproduce in SPUFI, then apply the specific fix.
Prevention checklist
- Always check SQLCODE after every EXEC SQL statement.
- Log the SQLCODE, SQLSTATE and failing statement for support.
