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

abs

1. ABS Function

======= abs | H2 Function | SQLDoc

abs

1. ABS Function

>>>>>>> 9d19b1c8cb744c8e86d5c15b74d8b5f719ad62be

The ABS function in H2 database is used to calculate the absolute value of a given number.

2. Syntax

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

ABS(number)

Arguments

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

Return

  • The ABS function returns the absolute value of the given number.

3. Notes

  • The ABS function in H2 database works on both positive and negative numbers.
  • If the input number is not a number or exceeds the numeric range, the ABS function will return NULL.
  • Remember to use the correct syntax and datatype while using the ABS function to avoid errors.

4. Examples

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

Example 1 - Calculating the absolute value of a positive number:

SELECT ABS(10) AS absolute_value;

Output:

absolute_value
--------------
10

Example 2 - Calculating the absolute value of a negative number:

SELECT ABS(-5) AS absolute_value;

Output:

absolute_value
--------------
5

Example 3 - Calculating the absolute value of numbers stored in a column:

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

INSERT INTO numbers VALUES (1, 10), (2, -7), (3, 0);

SELECT id, value, ABS(value) AS absolute_value
FROM numbers;

Output:

id | value | absolute_value
---+-------+----------------
1 | 10 | 10
2 | -7 | 7
3 | 0 | 0
  • CEILING - Round up to the nearest integer
  • floor - Round down to the nearest integer