List columns by name length in Db2 database

This query returns columns in a database sorted by their name.


select c.colname as column_name,
    length(c.colname) as column_name_length,
    c.tabschema as schema_name,
    c.tabname as table_name
from syscat.columns c
inner join syscat.tables t on 
      t.tabschema = c.tabschema and t.tabname = c.tabname
where t.type = 'T'
and t.tabschema not like 'SYS%'
order by column_name_length desc, 


  • column_name - column name
  • column_name_length - column name length
  • schema_name - column table schema name
  • table_name - column table name


  • One row represents one column of each table in a database
  • Scope of rows: each column that exists in a database
  • Ordered by length descrending - from longhest to shortest

Sample results

Comments are only visible when the visitor has consented to statistics cookies. To see and add comments please accept statistics cookies.
There are no comments. Click here to write the first comment.