← All errors

SQLCODE -158

SQL0158 Number of columns not consistent

IBM message text
Number of columns specified not consistent.
SQLCODE
-158
SQLSTATE
42811

Most common cause

In CREATE VIEW or CREATE TABLE AS the list of column names has a different number of entries from the SELECT that follows.

Other causes

  • A CTE column list (WITH name (a, b) AS ...) does not match its SELECT.
  • A SELECT * over a table whose structure changed in the meantime.

How to fix it

Align the name list with the SELECT, and avoid SELECT * in view definitions.

Text and codes from IBM documentation for 7.6. Checked on .