Here we will learn abs() function in SQLite and how to use SQLite abs() function to get the absolute value of a number.
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.
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.
Following are the simple examples of using SQLite ABS() function to get the absolute value of the given expression.
sqlite> SELECT abs(-9.3);
abs(-9.3)
----------
9.3
sqlite> SELECT abs(2 *-60);
abs(2 * -60)
-----------
120
sqlite> SELECT abs('-60');
abs('-60')
----------
60.0
sqlite> SELECT abs('Tutlane');
abs('Tutlane')
--------------
0.0
sqlite> SELECT abs('1000Tutlane');
abs('1000Tutlane')
------------------
1000.0
sqlite> SELECT abs('Tutlane1000');
abs('Tutlane1000')
----------
0.0
sqlite> SELECT abs(NULL);
abs(NULL)
----------
NULL
This is how we can use SQLite ABS() function to get the absolute value of a given expression.