SQLite ABS() Function

Here we will learn abs() function in SQLite and how to use SQLite abs() function to get the absolute value of a number.

SQLite ABS() Function

In SQLite abs() function is used to return the absolute value of a given expression. If given expression is an integer then an integer absolute value will be returned in case if the given expression contains float value then float absolute value will be returned.

 

In SQLite abs() function in case if given expression value NULL then abs() function will return NULL value.

 

If we give string or BLOB value for SQLite abs() function instead of the number parameter then it will return “0.0” value.

Syntax of SQLite ABS() Function

Following is the syntax of SQLite ABS() function to return the absolute value of the given expression.

 

abs( expression )

In above SQLite ABS() function syntax, we defined few parameters those are

 

Expression – It’s an expression or parameter to get the absolute value

 

Now we will see how to use SQLite ABS() function to get the absolute value of given number expression.

SQLite ABS() Function Examples

Following are the simple examples of using SQLite ABS() function to get the absolute value of the given expression.

 

sqliteSELECT abs(-9.3);

 

abs(-9.3)

----------

9.3

 

sqliteSELECT abs(2 *-60);

 

abs(2 * -60)

-----------

120

 

sqliteSELECT abs('-60');

 

abs('-60')

----------

60.0

 

sqliteSELECT abs('Tutlane');

 

abs('Tutlane')

--------------

0.0

 

sqliteSELECT abs('1000Tutlane');

 

abs('1000Tutlane')

------------------

1000.0

 

sqliteSELECT abs('Tutlane1000');

 

abs('Tutlane1000')

----------

0.0

 

sqliteSELECT abs(NULL);

 

abs(NULL)

----------

NULL

This is how we can use SQLite ABS() function to get the absolute value of a given expression.