MySQL ABS() Function

In MySQL, the ABS() function returns the absolute value of a specified number.

ABS() Syntax

Here is the syntax of MySQL ABS() function:

ABS(number)

Parameters

number
Required. The number whose absolute value is to be determined.

Return value

In MySQL, the ABS() function returns the absolute value of a number.

  • If the number parameter is a string, ABS() will try to convert it to a number according to the following rules:
    • If it starts with a number, convert the leading numbers to a number.
    • If it cannot be converted to a number, convert it to 0.
  • If the number parameter is NULL, ABS() will return NULL.

ABS() Examples

SELECT
    ABS(100),
    ABS(-100),
    ABS('100'),
    ABS('-100'),
    ABS('-100A'),
    ABS('A100'),
    ABS(NULL)\G

output

*************************** 1\. row ***************************
    ABS(100): 100
   ABS(-100): 100
  ABS('100'): 100
 ABS('-100'): 100
ABS('-100A'): 100
 ABS('A100'): 0
   ABS(NULL): NULL