SQLite ABS function

The SQLite ABS function is used to return the absolute value of a numeric expression. In other words, it returns the positive value of a number, regardless of whether it was originally positive or negative.

Syntax

The syntax for the ABS function in SQLite is as follows:

ABS(numeric_expression)

Where numeric_expression is the expression whose absolute value is to be returned.

Examples

Here are a few examples to illustrate how the ABS function works:

Example 1

SELECT ABS(-5);
Result: 5

In this example, the ABS function is used to return the absolute value of -5, which is 5.

Example 2

SELECT ABS(10);
Result: 10

In this example, the ABS function is used to return the absolute value of 10, which is also 10, since 10 is already a positive number.

Example 3

SELECT ABS(NULL);
Result: NULL

If the input to the ABS function is NULL, then the result will also be NULL.

In conclusion, the SQLite ABS function is a simple but useful function that allows you to quickly and easily return the absolute value of a numeric expression. It can be especially useful when dealing with calculations that involve both positive and negative numbers, and can help ensure that your results are accurate and consistent.