w3resource

SQLite abs() function

Description

SQLite abs() function returns the absolute value of a number.

  • The abs(X) function returns the absolute value of the numeric argument X. Abs(X) returns NULL if X is NULL.
  • abs(X) return 0.0 if X is a string or blob that cannot be converted to a numeric value.
  • If X is the integer -9223372036854775808 then abs(X) throws an integer overflow error since there is no equivalent positive 64-bit two complement value.

Syntax:

abs(X)

Argument

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

Example: SQLite abs() function

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

sqlite> SELECT abs(5);

Here is the result.

Sample Output:

abs(5)
----------
5

Example: SQLite abs() function using negative value

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

sqlite> SELECT abs(-5);

Here is the result.

Sample Output:


abs(-5)
----------
5

Previous: Sum()
Next: changes()



Become a Patron!

Follow us on Facebook and Twitter for latest update.

It will be nice if you may share this link in any developer community or anywhere else, from where other developers may find this content. Thanks.

https://w3resource.com/sqlite/core-functions-abs.php