SET_BIT function [Bit array]

Set the value of a specific bit in a bit array.

Syntax
SET_BIT([ bit-expression, ]bit-position [,  value ])
Parameters
  • bit-expression   The bit array in which to change the bit.

  • bit-position   The position of the bit to be set. This must be an unsigned integer.

  • value   The value to which the bit is to be set.

Returns

LONG VARBIT

Remarks

The default value of bit-expression is a bit array of length bit-position, containing all bits set to 0 (FALSE).

The default value of value is 1 (TRUE).

The result is NULL if any parameter is NULL.

The positions in the array are counted from the left side, starting at 1.

See also
Standards and compatibility
  • SQL/2003   Vendor extension.

Example

The following statement returns the value 00100011:

SELECT SET_BIT( '00110011', 4 , 0);

The following statement returns the value 00111011:

SELECT SET_BIT( '00110011', 5 , 1);

The following statement returns the value 00111011:

SELECT SET_BIT( '00110011', 5 );

The following statement returns the value 00001:

SELECT SET_BIT( 5 );