8.11.1 BITAND
Returns the bitwise logical AND of two binary data items.
- Organization of this subsection
(1) Specification format
scalar-function-BITAND ::= BITAND(target-data-1,target-data-2) target-data-1 ::= value-expression target-data-2 ::= value-expression
(2) Explanation of specification format
- target-data-1 and target-data-2:
-
Specifies the target binary data.
The following rules apply:
-
Specify target-data-1 and target-data-2 in the form of value expressions. For details about value expressions, see 7.20 Value expression.
-
Specify BINARY or VARBINARY type data for target-data-1 and target-data-2.
-
Make sure that target-data-1 and target-data-2 have the same data length (if the target data is BINARY type), or actual length (if the target data is VARBINARY type).
-
You cannot specify a dynamic parameter by itself for target-data-1.
-
If you specify a dynamic parameter by itself for target-data-2, the data type and data length of target-data-1 are assumed for the data type and data length of the dynamic parameter.
-
The following example illustrates the result of executing the scalar function BITAND.
- Examples:
-
Return the bitwise logical AND of two binary data items.
BITAND(B'01011011',B'01001110') → B'01001010'
BITAND(B'01011011',X'FF') → B'01011011'
BITAND(X'0F',X'FF') → X'0F'
(3) Rules
-
The execution result of the scalar function BITAND (the value of the nth bit) is shown in the following table.
Table 8‒35: Execution result of the scalar function BITAND (value of the nth bit) Value of the nth bit of target-data-1
Value of the nth bit of target-data-2
Execution result of the scalar function BITAND (value of the nth bit)
0
0
0
1
0
1
0
0
1
1
-
The data type and data length of the execution result are determined by the data types and data lengths of target-data-1 and target-data-2. The data type and data length of the execution result of the scalar function BITAND are shown in the following table.
Table 8‒36: Data type and data length of the execution result of the scalar function BITAND Data type and data length of target-data-1
Data type and data length of target-data-2
Data type and data length of the execution result
BINARY(m)
BINARY(m)
BINARY(m)
VARBINARY(Y)
Actual length of target data: m
VARBINARY(Y)
Actual length of target data: m
VARBINARY(X)
Actual length of target data: m
BINARY(m)
VARBINARY(X)
Actual length of target data: m
VARBINARY(Y)
Actual length of target data: m
VARBINARY(MAX(X,Y))
Actual length of target data: m
- Legend:
-
m: Data length or actual length
X: Data length (when X ≥ m)
Y: Data length (when Y ≥ m)
-
The NOT NULL constraint does not apply to the value of the execution result (the null value is allowed).
-
If either target-data-1 or target-data-2 has a null value, the execution result will be a null value.
-
If the actual length of target-data-1 and target-data-2 is 0 bytes, the execution result will be binary data whose actual length is 0 bytes.