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

ulshift

1. ULSHIFT Function

======= ulshift | H2 Function | SQLDoc

ulshift

1. ULSHIFT Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The ULSHIFT function in H2 database is used to perform a logical left shift on a given value.

2. Syntax

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

ULSHIFT(value, shift)

Arguments

  • value: The value to be shifted. It should be an integer or a binary value.
  • shift: The number of positions to shift the bits. It should be an integer.

Return

  • The ULSHIFT function returns the result of the logical left shift operation on the given value.

3. Notes

  • The ULSHIFT function in H2 database performs a logical left shift, which means the bits are shifted to the left and the vacant positions are filled with zeros.
  • If the value is negative or exceeds the bit length, the ULSHIFT function will return NULL.
  • Ensure that the value and shift arguments are of compatible types to avoid errors.

4. Examples

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

Example 1 - Performing a logical left shift on an integer value:

SELECT ULSHIFT(5, 2) AS result;

Output:

result
------
20

Example 2 - Performing a logical left shift on a binary value:

SELECT ULSHIFT(X'0A', 3) AS result;

Output:

result
------
80

Example 3 - Performing a logical left shift on a column value:

CREATE TABLE shift_values (
id INT PRIMARY KEY,
value INT,
shift INT
);

INSERT INTO shift_values VALUES (1, 10, 2), (2, 7, 1), (3, 15, 3);

SELECT id, value, shift, ULSHIFT(value, shift) AS result
FROM shift_values;

Output:

id | value | shift | result
---+-------+-------+-------
1 | 10 | 2 | 40
2 | 7 | 1 | 14
3 | 15 | 3 | 120
  • urshift - Perform logical right shift
  • bitand - Perform bitwise AND operation