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

rotateright

1. ROTATERIGHT Function

======= rotateright | H2 Function | SQLDoc

rotateright

1. ROTATERIGHT Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The ROTATERIGHT function in H2 database is used to rotate the bits of an integer value to the right by a specified number of positions.

2. Syntax

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

ROTATERIGHT(value, positions)

Arguments

  • value: The integer value whose bits need to be rotated.
  • positions: The number of positions to rotate the bits by. It should be a non-negative integer.

Return

  • The ROTATERIGHT function returns an integer value with the bits rotated to the right by the specified number of positions.

3. Notes

  • The ROTATERIGHT function in H2 database treats the input value as a 32-bit signed integer.
  • The number of positions to rotate can be greater than 32. In such cases, the positions are effectively reduced modulo 32 before performing the rotation.
  • If the input value is not a valid integer or the positions is negative, the ROTATERIGHT function will return NULL.
  • Ensure that the input value is within the range of a 32-bit signed integer to avoid unexpected results.

4. Examples

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

Example 1 - Rotating bits of an integer value:

SELECT ROTATERIGHT(10, 2) AS result;

Output:

result
------
2

Example 2 - Rotating bits of a column value:

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

INSERT INTO numbers VALUES (1, 15), (2, 7), (3, 20);

SELECT id, value, ROTATERIGHT(value, 3) AS rotated_value
FROM numbers;

Output:

id | value | rotated_value
---+-------+---------------
1 | 15 | 536870906
2 | 7 | 536870905
3 | 20 | 2