OCTET_LENGTH scalar function
The OCTET_LENGTH function returns the length of expression in octets (bytes).
The schema is SYSIBM.
-
expression
- An expression that returns a value that is a built-in string data type.
The result of the function is INTEGER. If the argument can be null, the result can be null; if the argument is null, the result is the null value.
The length of character or graphic strings includes trailing blanks. The length of binary strings includes binary zeros. The length of varying-length strings is the actual length and not the maximum length.
For greater portability, code your application to be able to accept a result of data type DECIMAL(31).
Examples
- Example 1: Assume that table T1 has a GRAPHIC(10) column
named C1.
returns the value 20.SELECT OCTET_LENGTH(C1) FROM T1
- Example 2: The following example works with the Unicode
string '&N~AB', where '&' is the musical symbol G clef character,
and '~' is the combining tilde character. This string is shown in
different Unicode encoding forms in the following example:
'&' 'N' '~' 'A' 'B' UTF-8 X'F09D849E' X'4E' X'CC83' X'41' X'42' UTF-16BE X'D834DD1E' X'004E' X'0303' X'0041' X'0042' Assume that the variables UTF8_VAR and UTF16_VAR contain the UTF-8 and the UTF-16BE representations of the string, respectively.
returns the values 9 and 12, respectively.SELECT OCTET_LENGTH(UTF8_VAR), OCTET_LENGTH(UTF16_VAR) FROM SYSIBM.SYSDUMMY1