SQL ABS Function

In SQL, The ABS function calculates the absolute value of a number or the result of an expression that evaluates to a number.

Syntax #

ABS (number | expression)Code language: SQL (Structured Query Language) (sql)

Arguments #

number | expression
Number or expression that evaluates to a number.

Return Type #

The ABS function returns the same data type as its argument.

Examples #

The following statement uses the ABS function to get the absolute value of -100:

SELECT ABS(-100);Code language: SQL (Structured Query Language) (sql)

Try it

Output:

abs
-------
100

The following example uses the ABS function to calculate the absolute value of an expression:

SELECT
  ABS(100 -300);Code language: SQL (Structured Query Language) (sql)

Try it

Output:

abs
-------
200

Summary #

  • Use the SQL ABS function to get the absolute value of number.
Was this tutorial helpful ?