OCTET_LENGTH Function

Returns the number of bytes in a string of any data type.

Category: Character
Returned data type: BIGINT

Syntax

OCTET_LENGTH(expression)

Arguments

expression

specifies any valid expression.

Data type All data types are valid.
See <sql-expression>
FedSQL Expressions

Details

The OCTET_LENGTH function counts a multibyte character as multiple characters. For example, if the specified string contains 6 two-byte characters, the OCTET_LENGTH function returns a value of 12.
If the character string is a bit string, the OCTET_LENGTH function returns the number of bytes it takes to hold the number of bits.

Comparisons

The CHARACTER_LENGTH function also returns the number of characters in a character string, but counts a multibyte character as a single character. The OCTET_LENGTH function counts a multibyte character as multiple characters.

Example

The following statements illustrate the OCTECT_LENGTH function:
Statements
Results
select octect_length('December');
8
select octet_length(B'0100011100');
2
select octet_length(x'FEA364BEA234');
6
select octet_length(' FedSQL ');
18

See Also

Last updated: February 23, 2017