CHARACTER_LENGTH or CHAR_LENGTH
The CHARACTER_LENGTH function returns the length of the first argument in the specified string unit.
Character string:
Graphic string:
The schema is SYSIBM.
Character string:
- character-expression
- An expression that returns a value of a built-in character string. character-expression cannot
be bit data.
The argument can also be a numeric data type. The numeric argument is implicitly cast to a VARCHAR data type.
- CODEUNITS16, CODEUNITS32, or OCTETS
- Specifies the unit that is used to express the length of the result.
- CODEUNITS16
- Specifies that the result is expressed in terms of 16-bit UTF-16 code units.
- CODEUNITS32
- Specifies that the result is expressed in terms of 32-bit UTF-32 code units.
- OCTETS
- Specifies the result is expressed in terms of bytes.
For more information about CODEUNITS16, CODEUNITS32, and OCTETS, see String unit specifications.
The result of the function is a large integer.
The result can be null; if the argument is null, the result is the null value.
The result is the length of character-expression expressed in the number of string units that were specified. The length of fixed-length strings includes trailing blanks. The length of varying-length strings is the actual length and not the maximum length.
Graphic string:
- graphic-expression
- An expression that returns a value of a built-in graphic string.
The argument can also be a numeric data type. The numeric argument is implicitly cast to a VARCHAR data type.
- CODEUNITS16 or CODEUNITS32
- Specifies the unit that is used to express the length of the result.
- CODEUNITS16
- Specifies that the result is expressed in terms of 16-bit UTF-16 code units.
- CODEUNITS32
- Specifies that the result is expressed in terms of 32-bit UTF-32 code units.
For more information about CODEUNITS16 and CODEUNITS32 see String unit specifications.
The result of the function is a large integer.
The result can be null; if the argument is null, the result is the null value.
The result is the length of graphic-expression expressed in the number of string units that were specified. The length of fixed-length 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';
The following two queries
return the value 7: SELECT CHARACTER_LENGTH(NAME,OCTETS)
FROM T1 WHERE NAME = 'Jürgen';
SELECT LENGTH(NAME)
FROM T1 WHERE NAME = 'Jürgen';