Search code examples
db2

DB2 - Count string characters, not length


I have a column on DB2 which we store a text. I want to know if there is a way to count how many characters are in a string, but without using the Length() function, let me explain. We have a string with exactly 1,000 characters, as you can see here: IMAGE

The total lentgh is 1,064, while there are 1,000 total characters, this is due to the non-western characters (the chinese and korean ones). So the DB2 Length() function also returns 1,064 in the query: IMAGE

Is there a way to make DB2 returns 1,000 in this query instead of 1,064? Thanks!


Solution

  • Use CHARACTER_LENGTH()

    Availability may depend on your DB2 platform and version..