DB2 Scalar functions - CHARACTER_LENGTH
The CHARACTER_LENGTH function returns the length, in the specified string unit, of an expression.
The schema is SYSIBM.
If a string unit argument is not specified and expression is a character string that is not FOR BIT DATA or is a graphic string, the default is CODEUNITS32. Otherwise, the default is OCTETS.
For more information, see "String units in built-in functions" in "Character strings".
The result of the function is a large integer. If the argument can be null, the result can be null; if the argument is null, the result is the null value.
The length of character and graphic strings includes trailing blanks. The length of varying-length strings is the actual length and not the maximum length.
SELECT CHARACTER_LENGTH(NAME, CODEUNITS32) FROM T1 WHERE NAME = 'Jürgen' SELECT CHARACTER_LENGTH(NAME, CODEUNITS16) FROM T1 WHERE NAME = 'Jürgen'
SELECT CHARACTER_LENGTH(NAME, OCTETS) FROM T1 WHERE NAME = 'Jürgen' SELECT LENGTH(NAME) FROM T1 WHERE NAME = 'Jürgen'
Assume that the variable UTF8_VAR contains the UTF-8 representation of the string.
SELECT CHARACTER_LENGTH(UTF8_VAR, CODEUNITS16) , CHARACTER_LENGTH(UTF8_VAR, CODEUNITS32) , CHARACTER_LENGTH(UTF8_VAR, OCTETS) FROM SYSIBM.SYSDUMMY1
Assume that the variable UTF16_VAR contains the UTF-16BE representation of the string.
SELECT CHARACTER_LENGTH(UTF16_VAR, CODEUNITS16) , CHARACTER_LENGTH(UTF16_VAR, CODEUNITS32) , CHARACTER_LENGTH(UTF16_VAR, OCTETS) FROM SYSIBM.SYSDUMMY1