totn SQLite Functions

SQLite: abs Function

This SQLite tutorial 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);
Result: 5

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

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

sqlite> SELECT abs(12.79);
Result: 12.79

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

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

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

sqlite> SELECT abs(NULL);
Result: NULL

sqlite> SELECT abs('TechOnTheNet');
Result: 0.0