<< BIN_XOR() | FB 2.5 Language Reference | CAST() >>
<< BIN_XOR() | FB 2.1 Language Reference | CAST() >>

BIT_LENGTH()

Available in: DSQL, PSQL

Added in: 2.0

Changed in: 2.1

Description

Gives the length in bits of the input string. For multi-byte character sets, this may be less than the number of characters times 8 times the "formal" number of bytes per character as found in RDB$CHARACTER_SETS.

Note: With arguments of type CHAR, this function takes the entire formal string length (e.g. the declared length of a field or variable) into account. If you want to obtain the "logical" bit length, not counting the trailing spaces, right-TRIM the argument before passing it to BIT_LENGTH.

Result type: INTEGER

Syntax

 BIT_LENGTH (str)

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

Examples

 select bit_length('Hello!') from rdb$database
   -- returns 48

 select bit_length(_iso8859_1 'Gr di!') from rdb$database
   -- returns 64:  and  take up one byte each in ISO8859_1

 select bit_length
   (cast (_iso8859_1 'Gr di!' as varchar(24) character set utf8))
 from rdb$database
   -- returns 80:  and  take up two bytes each in UTF8

 select bit_length
   (cast (_iso8859_1 'Gr di!' as char(24) character set utf8))
 from rdb$database
   -- returns 208: all 24 CHAR positions count, and two of them are 16-bit

See also:
OCTET_LENGTH()
CHARACTER_LENGTH()
Firebird Null Guide: Internal functions and directives

back to top of page
<< BIN_XOR() | FB 2.5 Language Reference | CAST() >>
<< BIN_XOR() | FB 2.1 Language Reference | CAST() >>