Please note, this is a STATIC archive of website www.w3resource.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
w3resource

MySQL ABS() function

ABS() function

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

Syntax:

 ABS(N); 

Argument:

Name Description
N A number whose absolute value is to be retrieved.

Syntax Diagram:

MySQL ABS() Function - Syntax Diagram

MySQL Version: 5.6


Pictorial presentation of MySQL ABS() function

pictorial presentation of mysql function

Example:

The following MySQL statement will return the absolute value of a positive number specified in the argument.

Code:

SELECT ABS(5);

Sample Output:

mysql> SELECT ABS(5);
+--------+
| ABS(5) |
+--------+
|      5 | 
+--------+
1 row in set (0.01 sec)

Example : ABS() function using negative value

The following MySQL statement will return the absolute value of a negative number defined in the argument.

Code:

SELECT ABS(-5);

Sample Output:

mysql> SELECT ABS(-5);
+---------+
| ABS(-5) |
+---------+
|       5 | 
+---------+
1 row in set (0.01 sec)

All Mathematical Functions

MySQL Mathematical Functions, slide presentation

Previous: UPPER
Next: ACOS()