Search code examples
db2varchar

IBM DB2 9.7 VARCHAR([N]), does [N] stand for characters or bytes in UTF-8


We use UTF-8 encoding in our IBM DB2 9.7 LUW database. Even though I did a lot of searching I could not find a definite answer to this question. If I define a table column to be VARCHAR(100), does it mean 100 characters or 100 bytes?


Solution

  • As per the online IBM docs, it's in bytes:

    VARCHAR(integer), or CHARACTER VARYING(integer), or CHAR VARYING(integer)

    For a varying-length character string of maximum length integer bytes, which may range from 1 to 32,672.

    There's further information on this page where you can see

    SELECT CHARACTER_LENGTH (NAME, OCTETS) FROM T1 WHERE NAME = 'Jürgen'
    

    gives you 7 because ü is encoded as x'c3bc'.