8.15.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.21 Value expression.
-
You cannot specify array data and structure data for the target data.
-
You cannot specify a dynamic parameter by itself for the target data.
-
(3) Rules
-
The data type of the execution result is the BIGINT type#.
- #
-
If the integer data type format is a legacy format, it will be an 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‒61: Value of execution result for each target data type No.
Data type of target data
Value of execution result (bytes)
1
BIGINT
8
2
INTEGER
4#1
3
SMALLINT
2#2
4
DECIMAL
or
NUMERIC
When the precision is 1 to 4
2
5
When the precision is 5 to 8
4
6
When the precision is 9 to 16
8
7
When the precision is 17 to 38
16
8
DOUBLE PRECISION or FLOAT
8
9
REAL
4
10
CHAR(n)
n
11
VARCHAR
Actual length
12
STRING
Actual length
13
DATE
4
14
TIME(p)
3 + ↑p ÷ 2↑
15
TIMESTAMP(p)
7 + ↑p ÷ 2↑
16
BINARY(n)
n
17
VARBINARY
Actual length
18
BOOLEAN
1
19
UUID
16
- #1
-
If the integer data type format is a legacy format, it is 8 bytes.
- #2
-
If the integer data type format is a legacy format, it is 4 bytes.
(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"