MySQL ABS() Function
Updated on
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
ABS() returns the absolute value of its argument, or NULL if the argument is NULL. The result type is derived from the argument type. The minimum signed BIGINT value has no positive counterpart in the signed range, so ABS(-9223372036854775808) returns an error. See MySQL’s mathematical function reference and our guide to ABS() type behavior and edge cases.
- If
numberis a string, MySQL evaluates it in a numeric context. A partially numeric string can be truncated during conversion, and nonnumeric text can convert to0with a warning. Validate or explicitly cast imported text instead of relying on implicit conversion; see type conversion in expression evaluation. - If
numberisNULL,ABS()returnsNULL.
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