Firebird Documentation IndexFirebird 2.5 Language Ref. UpdateInternal functions → CHAR_LENGTH(), CHARACTER_LENGTH()
Firebird Home Firebird Home Prev: CEIL(), CEILING()Firebird Documentation IndexUp: Internal functionsNext: CHAR_TO_UUID()

CHAR_LENGTH(), CHARACTER_LENGTH()

Tip

Find a more recent version at Firebird 5.0 Language Reference: CHAR_LENGTH(), CHARACTER_LENGTH()

Available in: DSQL, PSQL

Added in: 2.0

Changed in: 2.1

Description: Gives the length in characters of the input string.

Note

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.

Result type: INTEGER

Syntax: 

CHAR_LENGTH (str)
CHARACTER_LENGTH (str)

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

Examples: 

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

See also: BIT_LENGTH(), OCTET_LENGTH()

Prev: CEIL(), CEILING()Firebird Documentation IndexUp: Internal functionsNext: CHAR_TO_UUID()
Firebird Documentation IndexFirebird 2.5 Language Ref. UpdateInternal functions → CHAR_LENGTH(), CHARACTER_LENGTH()