Firebird Documentation IndexFirebird 2.0 Language Ref. UpdateInternal functions → OCTET_LENGTH()
Firebird Home Firebird Home Prev: NULLIF()Firebird Documentation IndexUp: Internal functionsNext: RDB$GET_CONTEXT()

OCTET_LENGTH()

Tip

Find a more recent version at Firebird 5.0 Language Reference: OCTET_LENGTH()

Available in: DSQL, PSQL

Added in: 2.0

Description: Gives the length in bytes (octets) of the input string. For multi-byte character sets, this may be less than the number of characters 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 byte length, not counting the trailing spaces, right-TRIM the argument before passing it to OCTET_LENGTH.

Result type: INTEGER

Syntax: 

OCTET_LENGTH (str)

Examples: 

select octet_length('Hello!') from rdb$database
  -- returns 6
select octet_length(_iso8859_1 'Grüß di!') from rdb$database
  -- returns 8: ü and ß take up one byte each in ISO8859_1
select octet_length
  (cast (_iso8859_1 'Grüß di!' as varchar(24) character set utf8))
from rdb$database
  -- returns 10: ü and ß take up two bytes each in UTF8
select octet_length
  (cast (_iso8859_1 'Grüß di!' as char(24) character set utf8))
from rdb$database
  -- returns 26: all 24 CHAR positions count, and two of them are 2-byte

See also: BIT_LENGTH(), CHARACTER_LENGTH

Prev: NULLIF()Firebird Documentation IndexUp: Internal functionsNext: RDB$GET_CONTEXT()
Firebird Documentation IndexFirebird 2.0 Language Ref. UpdateInternal functions → OCTET_LENGTH()