<<<<<<< HEAD bitget | H2 | SQLDoc
Skip to main content

bitget

1. BITGET Function

======= bitget | H2 Function | SQLDoc

bitget

1. BITGET Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The BITGET function in H2 database is used to get the value of a specific bit from a binary string or BLOB.

2. Syntax

The syntax for the BITGET function in H2 database is as follows:

BITGET(expr, position)

Arguments

  • expr: The binary string or BLOB from which to extract the bit value.
  • position: The position of the bit to extract. The position starts from 0, representing the least significant bit.

Return

  • The BITGET function returns the value of the specified bit (0 or 1) as an integer.

3. Notes

  • The BITGET function in H2 database works with binary strings or BLOBs.
  • If the input binary string or BLOB is empty or null, the BITGET function will return null.
  • The position argument should be within the valid range of the binary string or BLOB length. If the position exceeds the length, the BITGET function will return null.
  • If the binary string or BLOB contains characters that are not valid binary digits (0 or 1), the BITGET function will return null.
  • Remember to use the correct syntax and datatype while using the BITGET function to avoid errors.

4. Examples

Here are a few examples demonstrating the usage of the BITGET function in H2 database:

Example 1 - Getting the value of the second bit from a binary string:

SELECT BITGET(B'101010', 1) AS bit_value;

Output:

bit_value
---------
0

Example 2 - Getting the value of the seventh bit from a BLOB column:

CREATE TABLE data (
id INT PRIMARY KEY,
binary_data BLOB
);

INSERT INTO data VALUES (1, B'11001110'), (2, B'10101010');

SELECT id, BITGET(binary_data, 6) AS bit_value
FROM data;

Output:

id | bit_value
---+----------
1 | 0
2 | 1
  • bitand - Bitwise AND operation
  • bitor - Bitwise OR operation
  • bitxor - Bitwise XOR operation