DB2 10.5 for Linux, UNIX, and Windows

CHARACTER_LENGTH scalar function

The CHARACTER_LENGTH function returns the length of expression in the specified string unit.

Read syntax diagramSkip visual syntax diagram
>>-+-CHARACTER_LENGTH-+----------------------------------------->
   '-CHAR_LENGTH------'   

>----(--expression--,--+-CODEUNITS16-+--)----------------------><
                       +-CODEUNITS32-+        
                       '-OCTETS------'        

The schema is SYSIBM.

expression
An expression that returns a value of a built-in character or graphic string.
CODEUNITS16, CODEUNITS32, or OCTETS
Specifies the string unit of the result. CODEUNITS16 specifies that the result is to be expressed in 16-bit UTF-16 code units. CODEUNITS32 specifies that the result is to be expressed in 32-bit UTF-32 code units. OCTETS specifies that the result is to be expressed in bytes.

If a string unit is specified as CODEUNITS16 or CODEUNITS32, and expression is a binary string or bit data, an error is returned (SQLSTATE 428GC). If a string unit is specified as OCTETS and expression is a binary string, an error is returned (SQLSTATE 42815). For more information about CODEUNITS16, CODEUNITS32, and OCTETS, 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.

Examples