rotateleft
1. ROTATELEFT Function
=======rotateleft
1. ROTATELEFT Function
>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62beThe ROTATELEFT function in H2 database is used to rotate the bits of a given number to the left by a specified number of positions.
2. Syntax
The syntax for the ROTATELEFT function in H2 database is as follows:
ROTATELEFT(number, positions)
Arguments
number
: The number whose bits need to be rotated to the left. It should be an integer value.positions
: The number of positions by which the bits should be rotated. It should be a non-negative integer value.
Return
- The ROTATELEFT function returns the result of rotating the bits of the given number to the left by the specified number of positions.
3. Notes
- The ROTATELEFT function in H2 database operates on the binary representation of the number.
- If the input number is negative, it is treated as a 32-bit signed integer.
- The number of positions can be greater than the number of bits in the number. In such cases, the bits are rotated modulo the number of bits.
- If the input number or positions are not integers, the ROTATELEFT function will return
NULL
. - Ensure that the input number and positions are within the appropriate range to avoid unexpected results or errors.
4. Examples
Here are a few examples demonstrating the usage of the ROTATELEFT function in H2 database:
Example 1 - Rotating the bits of a number to the left by 2 positions:
SELECT ROTATELEFT(5, 2) AS result;
Output:
result
------
20
Example 2 - Rotating the bits of a column to the left:
CREATE TABLE numbers (
id INT PRIMARY KEY,
value INT
);
INSERT INTO numbers VALUES (1, 10), (2, 15), (3, 7);
SELECT id, value, ROTATELEFT(value, 3) AS rotated_value
FROM numbers;
Output:
id | value | rotated_value
---+-------+--------------
1 | 10 | 80
2 | 15 | 120
3 | 7 | 56
5. Related Functions
- rotateright - Rotate bits to the right
- bitand - Bitwise AND operation
- bitor - Bitwise OR operation