OCTET_LENGTH
Takes one argument as an input and returns the string length in octets for all string types.
	Takes one argument as an input and returns the string length in octets for all string types.
Behavior type
ImmutableSyntax
OCTET_LENGTH ( expression )
Arguments
- expression
- (CHAR or VARCHAR or BINARY or VARBINARY) is the string to measure.
Notes
- 
If the data type of expressionis a CHAR, VARCHAR or VARBINARY, the result is the same as the actual length ofexpressionin octets. For CHAR, the length does not include any trailing spaces.
- 
If the data type of expressionis BINARY, the result is the same as the fixed-length ofexpression.
- 
If the value of expressionis NULL, the result is NULL.
Examples
| Expression | Result | 
|---|---|
| SELECT OCTET_LENGTH(CHAR(10) '1234  '); | 4 | 
| SELECT OCTET_LENGTH(CHAR(10) '1234'); | 4 | 
| SELECT OCTET_LENGTH(CHAR(10) '  1234'); | 6 | 
| SELECT OCTET_LENGTH(VARCHAR(10) '1234  '); | 6 | 
| SELECT OCTET_LENGTH(VARCHAR(10) '1234 '); | 5 | 
| SELECT OCTET_LENGTH(VARCHAR(10) '1234'); | 4 | 
| SELECT OCTET_LENGTH(VARCHAR(10) '  1234'); | 7 | 
| SELECT OCTET_LENGTH('abc'::VARBINARY); | 3 | 
| SELECT OCTET_LENGTH(VARBINARY 'abc'); | 3 | 
| SELECT OCTET_LENGTH(VARBINARY 'abc  '); | 5 | 
| SELECT OCTET_LENGTH(BINARY(6) 'abc'); | 6 | 
| SELECT OCTET_LENGTH(VARBINARY ''); | 0 | 
| SELECT OCTET_LENGTH(''::BINARY); | 1 | 
| SELECT OCTET_LENGTH(null::VARBINARY); | |
| SELECT OCTET_LENGTH(null::BINARY); |