9.6. 二元字串函式及運算子
This section describes functions and operators for examining and manipulating bit strings, that is values of the typesbit
andbit varying
. Aside from the usual comparison operators, the operators shown inTable 9.13can be used. Bit string operands of&
,|
, and#
must be of equal length. When bit shifting, the original length of the string is preserved, as shown in the examples.
Table 9.13. Bit String Operators
Operator | Description | Example | Result | ||||
` | ` | concatenation | `B'10001' | B'011'` |
| ||
| bitwise AND |
|
| ||||
` | ` | bitwise OR | `B'10001' | B'01101'` |
| ||
| bitwise XOR |
|
| ||||
| bitwise NOT |
|
| ||||
| bitwise shift left |
|
| ||||
| bitwise shift right |
|
|
The followingSQL-standard functions work on bit strings as well as character strings:length
,bit_length
,octet_length
,position
,substring
,overlay
.
The following functions work on bit strings as well as binary strings:get_bit
,set_bit
. When working with a bit string, these functions number the first (leftmost) bit of the string as bit 0.
In addition, it is possible to cast integral values to and from typebit
. Some examples:
Note that casting to just“bit”means casting tobit(1)
, and so will deliver only the least significant bit of the integer.
Note
Casting an integer tobit(n)
copies the rightmostn
bits. Casting an integer to a bit string width wider than the integer itself will sign-extend on the left.
Last updated