8.12.2 BIN
Converts binary data to a binary string representation (character string data consisting of 0 and 1).
- Organization of this subsection
(1) Specification format
scalar-function-BIN ::= BIN(target-data) target-data ::= value-expression
(2) Explanation of specification format
- target-data:
-
Specifies the target binary data.
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.
-
Specify BINARY or VARBINARY type data for the target data.
-
You cannot specify a dynamic parameter by itself for the target data.
-
You cannot specify binary data whose defined length is 4,001 bytes or greater for the target data.
-
The following example illustrates the result of executing the scalar function BIN.
- Examples:
-
BIN(B'10100100') → '10100100'
BIN(X'A4') → '10100100'
(3) Rules
-
The data type and data length of the execution result are shown in the following table.
Table 8‒44: Data type and data length of the execution result of the scalar function BIN Data type and data length of target data
Data type and data length of the execution result
Data type
Defined length
Actual length
Data type
Defined length
Actual length
BINARY(n)
1 ≤ n ≤ 4,000
Not applicable.
VARCHAR
n × 8
n × 8
VARBINARY(n)
1 ≤ n ≤ 4,000
r
r × 8
- Legend:
-
n: Defined length of target data
r: Actual length of target data
-
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.
-
If the actual length of the target data is 0 bytes, the execution result will be data with an actual length of 0 bytes.