abs function

The abs function returns the absolute value of the input expression.

Syntax:
number abs(n)

Semantics:

  • n: The argument n is an expression that resolves to a number.
  • return type: number.
    • Returns the same type as the argument n.
    • Returns a NULL value in the following cases:
      • n resolves to a NULL value
      • n does not resolve to a number
    • Returns a positive infinity if n resolves to a positive/negative infinity.
    • Returns NaN if n resolves to NaN.
    • Returns a zero if n resolves to a positive/negative zero.
    • Returns Integer.MIN_VALUE if n resolves to an integer type value and is equal to Integer.MIN_VALUE.
    • Returns Long.MIN_VALUE if n resolves to a long type value and is equal to Long.MIN_VALUE.
Example:
SELECT abs(n) FROM Userstocks
Value of n Output
10 10
-10 10
1.67 1.67
-1.67 1.67