Skip to main content

sign

1. SIGN Function

The SIGN function in H2 database is used to determine the sign of a given number.

2. Syntax

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

SIGN(number)

Arguments

  • number: The number for which the sign needs to be determined. It should be a numeric value.

Return

  • The SIGN function returns the sign of the given number. It returns:
    • -1 if the number is negative.
    • 0 if the number is zero.
    • 1 if the number is positive.

3. Notes

  • The SIGN function in H2 database works with both integer and floating-point numbers.
  • If the input number is NULL, the SIGN function will return NULL.
  • Use the SIGN function to determine the sign of a number and perform different operations based on the sign.
  • Ensure that the input number is of the correct datatype to avoid errors.

4. Examples

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

Example 1 - Determining the sign of a positive number:

SELECT SIGN(10) AS sign;

Output:

sign
----
1

Example 2 - Determining the sign of a negative number:

SELECT SIGN(-5) AS sign;

Output:

sign
----
-1

Example 3 - Determining the sign of zero:

SELECT SIGN(0) AS sign;

Output:

sign
----
0

Example 4 - Using the SIGN function in a WHERE clause:

SELECT id, value
FROM mytable
WHERE SIGN(value) = -1;

Output:

id | value
---+-------
1 | -5
3 | -10
  • abs - Calculate absolute value
  • round - Round to the nearest integer