CHAR_LENGTH: Finding the Length of a Character String

How to:

The CHAR_LENGTH function returns the length of a character string. CHARACTER_LENGTH is identical to CHAR_LENGTH.

This function is most useful for columns described as VARCHAR (variable length character). For example, if a column described as GLOSS VARCHAR(10) contains

'bryllig'
'slythy '
'toves  '

then CHAR_LENGTH(GLOSS) would return

7
6
5

If the column is described as CHAR (non-variable length character), the same number is returned for all rows. In this case, CHAR_LENGTH(GLOSS) would return

10
10
10

To avoid counting trailing blanks use CHAR_LENGTH(TRIM (TRAILING FROM GLOSS)). See TRIM: Removing Leading or Trailing Characters (SQL) for details.


Top of page

x
Syntax: How to Find the Length of a Character String
CHAR_LENGTH(arg)

where:

arg

Character string

Is the value whose length is to be determined.

This function returns an integer value.



Example: Finding the Length of a Character String

CHAR_LENGTH finds the length of the string. This example,

CHAR_LENGTH('abcdef')

returns 6.

This example,

CHAR_LENGTH('abcdef   ')

returns 9, since trailing blanks are counted.


iWay Software