SQL/MX 2.x Reference Manual (H06.04+)

SQL/MX Functions and Expressions
HP NonStop SQL/MX Reference Manual540440-003
9-101
OCTET_LENGTH Function
OCTET_LENGTH Function
The OCTET_LENGTH function returns the length of a character string in bytes.
string-value-expression
specifies the string value expression for which to return the length in bytes.
NonStop SQL/MX returns the result as a 2-byte signed integer with a scale of zero.
If string-value-expression is null, NonStop SQL/MX returns a length of zero.
See Character Value Expressions on page 6-37.
Considerations for OCTET_LENGTH
CHAR and VARCHAR Operands
For a column declared as fixed CHAR, NonStop SQL/MX returns the length of that
column as the maximum number of storage bytes. For a VARCHAR column,
NonStop SQL/MX returns the length of the string stored in that column as the actual
number of storage bytes.
Similarity to CHAR_LENGTH Function
The OCTET_LENGTH and CHAR_LENGTH functions are similar. The
OCTET_LENGTH function returns the number of bytes, rather than the number of
characters, in the string. This distinction is important for multibyte implementations. For
an example of selecting a double-byte column, see Similarity to OCTET_LENGTH
Function on page 9-24.
Examples of OCTET_LENGTH
If a character string is stored as two bytes for each character, this function returns
the value 12. Otherwise, the function returns 6:
OCTET_LENGTH ('Robert')
OCTET_LENGTH (string-value-expression)