8.3.4. CHAR_LENGTH(), CHARACTER_LENGTH()

Available in

DSQL, PSQL

Syntax

  1. CHAR_LENGTH (string)
  2. | CHARACTER_LENGTH (string)
Table 126. CHAR[ACTER]_LENGTH Function Parameter
ParameterDescription

string

An expression of a string type

Result type

INTEGER

Description

Gives the length in characters of the input string.

Notes
  • With arguments of type CHAR, this function returns the formal string length (i.e. the declared length of a field or variable). If you want to obtain the “logical” length, not counting the trailing spaces, right-TRIM the argument before passing it to CHAR[ACTER]_LENGTH.

  • BLOB support: Since Firebird 2.1, this function fully supports text BLOBs of any length and character set.

Examples

  1. select char_length('Hello!') from rdb$database
  2. -- returns 6
  3. select char_length(_iso8859_1 'Grüß di!') from rdb$database
  4. -- returns 8
  5. select char_length
  6. (cast (_iso8859_1 'Grüß di!' as varchar(24) character set utf8))
  7. from rdb$database
  8. -- returns 8; the fact that ü and ß take up two bytes each is irrelevant
  9. select char_length
  10. (cast (_iso8859_1 'Grüß di!' as char(24) character set utf8))
  11. from rdb$database
  12. -- returns 24: all 24 CHAR positions count

See also

BIT_LENGTH(), OCTET_LENGTH()