8.14.1 LENGTHB
Returns the length of the target data in bytes.
- Organization of this subsection
(1) Specification format
scalar-function-LENGTHB ::= LENGTHB(target-data) target-data ::= value-expression
(2) Explanation of specification format
- target-data:
-
Specifies the target data whose length is to be determined.
The following rules apply:
-
Specify the target data in the form of a value expression. For details about value expressions, see 7.20 Value expression.
-
For the target data, specify numeric data, character string data, datetime data, or binary data.
-
You cannot specify a dynamic parameter by itself for the target data.
-
(3) Rules
-
The data type of the execution result is the INTEGER type.
-
The NOT NULL constraint does not apply to the value of the execution result (the null value is allowed).
-
If the target data has a null value, the execution result will be a null value.
-
The following table shows the value of the execution result for each target data type.
Table 8‒58: Value of execution result for each target data type No.
Data type of target data
Value of execution result (bytes)
1
INTEGER
8
2
SMALLINT
4
3
DECIMAL
When the precision is 1 to 4
2
4
When the precision is 5 to 8
4
5
When the precision is 9 to 16
8
6
When the precision is 17 to 38
16
7
DOUBLE PRECISION
8
8
CHAR(n)
n
9
VARCHAR
Actual length
10
DATE
4
11
TIME(p)
3 + ↑p ÷ 2↑
12
TIMESTAMP(p)
7 + ↑p ÷ 2↑
13
BINARY(n)
n
14
VARBINARY
Actual length
(4) Example
- Example 1 (in a case where the target data is character string data)
-
Determine the actual lengths of the VARCHAR type data in column C1 from table T1.
The assumed character encoding is Unicode (UTF-8).
SELECT LENGTHB("C1") FROM "T1"
- Example 2 (in a case where the target data is binary data)
-
Determine the actual data length for each row of columns C1 (VARBINARY(5)) and C2 (BINARY(5)) in table T1.
SELECT LENGTHB("C1"), LENGTHB("C2") FROM "T1"