ABS
Description
The ABS
function is used to calculate the absolute value of a given numerical expression. Whether the input value is positive or negative, the ABS
function can return the corresponding non-negative value.
Syntax
Parameters
expr
: A numeric expression for which the absolute value needs to be calculated. It can besmallint
,tinyint
,int
,bigint
,decimal
,double
, orfloat
.
Return Value
Returns the absolute value of the parameter expr
. The return type is the same as the input parameter type.
Example Usage
- Calculate the absolute value of a negative integer:
- Calculate the absolute value of a positive integer:
- Calculate the absolute value of a decimal:
- Calculate the absolute value of a negative number with a decimal point:
- Calculate the absolute value of a
decimal
type:
- Use the
ABS
function in a query to get the absolute value of employee salaries:
Notes
- When
expr
isNULL
, theABS
function will returnNULL
. - The
ABS
function can be used in conjunction with other SQL functions, such as when sorting or filtering queries.