This section describes functions and operators for examining and manipulating bit strings, that is values of the types
bit varying. Aside from the usual comparison operators, the operators shown in Table 9.14 can be used. Bit string operands of
#must be of equal length. When bit shifting, the original length of the string is preserved, as shown in the examples.
The following SQL-standard functions work on bit strings as well as character strings:
The following functions work on bit strings as well as binary strings:
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 type
bit. Some examples:
cast(-44 as bit(12)) 111111010100
Note that casting to just “bit” means casting to
bit(1), and so will deliver only the least significant bit of the integer.
Casting an integer to
bit(n)copies the rightmost
nbits. Casting an integer to a bit string width wider than the integer itself will sign-extend on the left.\