ABS
Overview
The ABS()
function returns an absolute number, i.e., the positive value of a number. The data type of the returned value will depend on the data type of the value passed to the ABS()
function.
Syntax
The syntax for the ABS()
function is as follows:
The ABS()
function requires one argument:
x
: An expression that evaluates to a number.
Examples
Case #1: Absolute value of a negative number
The following example demonstrates how the ABS()
function can be used to obtain the absolute value of a negative number:
It will return an absolute value of the passed argument:
Case #2: ABS() function with an expression
The following example demonstrates how the ABS()
function can be used with an expression to obtain the absolute value of the result:
The result of the above statement is -150. However, you will get the output 150, as 150 is the positive version of -150.
Case #3: Using the ABS() function with a table
The following example demonstrates how the ABS()
function can be used with a table to obtain the absolute values of all numbers in a specific column:
- First, create a table named absTable containing an initialValue column with some positive and negative values:
- Next, use the following query to find the absolute value of all numbers:
- The above query will retrieve all values in the “initialValue” column and their absolute values in the “absoluteValue” column. The output will look something like this: