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

rshift

1. RSHIFT Function

======= rshift | H2 Function | SQLDoc

rshift

1. RSHIFT Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The RSHIFT function in H2 database is used to perform a right shift operation on a given integer value.

2. Syntax

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

RSHIFT(value, n)

Arguments

  • value: The integer value on which the right shift operation needs to be performed.
  • n: The number of positions to shift the bits to the right. It should be a non-negative integer value.

Return

  • The RSHIFT function returns the result of the right shift operation on the given value.

3. Notes

  • The RSHIFT function in H2 database performs a logical right shift operation, which means the leftmost bit is filled with zeros.
  • If the input value is not a valid integer or the shift count n is negative, the RSHIFT function will return NULL.
  • Ensure that the datatype of the input value is compatible with the RSHIFT function to avoid errors.

4. Examples

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

Example 1 - Performing a right shift operation on a single value:

SELECT RSHIFT(8, 2) AS result;

Output:

result
------
2

Example 2 - Performing a right shift on values stored in a column:

CREATE TABLE numbers (
id INT PRIMARY KEY,
value INT
);

INSERT INTO numbers VALUES (1, 16), (2, 10), (3, 5);

SELECT id, value, RSHIFT(value, 2) AS result
FROM numbers;

Output:

id | value | result
---+-------+--------
1 | 16 | 4
2 | 10 | 2
3 | 5 | 1
  • lshift - Perform a left shift operation
  • bitand - Perform a bitwise AND operation
  • bitor - Perform a bitwise OR operation
  • bitxor - Perform a bitwise XOR operation