Sqlite Abs Function

SQLite: abs Function

This SQLite post explains how to use the SQLite abs function with syntax and examples.

Description

The SQLite abs function returns the absolute value of a number.

Syntax

The syntax for the abs function in SQLite is:

abs( number )

Parameters or Arguments

number

The number to convert to an absolute value.

Note

  • The abs function returns NULL, if the number parameter is a NULL value.
  • The abs function returns 0.0, if the number parameter is a string or blob that does not evaluate to a numeric value.

Applies To

The abs function can be used in the following versions of SQLite:

  • SQLite 3.8.6, SQLite 3.8.x, SQLite 3.7.x, SQLite 3.6.x

Example

Let's look at some SQLite abs function examples and explore how to use the abs function in SQLite.

For example:

sqlite> SELECT abs(-5);
Output: 5

sqlite> SELECT abs(-5.7);
Output: 5.7

sqlite> SELECT abs(7 - 10);
Output: 3

sqlite> SELECT abs(12.79);
Output: 12.79

sqlite> SELECT abs(25 * -2);
Output: 50

sqlite> SELECT abs(-3);
Output: 3

sqlite> SELECT abs('-3');
Output: 3.0

sqlite> SELECT abs(NULL);
Output: NULL

sqlite> SELECT abs('AODBA');
Output: 0.0