Number Functions
- reference
Number functions perform various mathematical calculations and transformations on numeric data.
ABS(expression)
ACOS(expression)
Returns the arccosine (inverse cosine) value of a numeric expression, in radians.
ASIN(expression)
Returns the arcsine (inverse sine) value of a numeric expression, in radians.
ATAN(expression)
ATAN2(expression1, expression2)
Returns the arctangent (inverse tangent) value of 2 numeric expressions (expression1/expression2), in radians.
Arguments
- expression1
-
[Required] A valid numeric expression representing the y-coordinate.
- expression2
-
[Required] A valid numeric expression representing the x-coordinate.
Return Value
The function returns 1 of the following:
-
A number representing the arctangent value in radians.
-
0if both input values are0. -
NULLif either input is a non-numeric value orNULL.
Example
SELECT ATAN2(1, 1) AS atan2Value_1,
ATAN2(1, -1) AS atan2Value_2,
ATAN2(-1, -2) AS atan2Value_3,
ATAN2(0, 0) AS atan2Value_5;
[
{
"atan2Value_1": 0.7853981633974483,
"atan2Value_2": 2.356194490192345,
"atan2Value_3": -2.677945044588987,
"atan2Value_5": 0
}
]
CEIL(expression)
COS(expression)
DEGREES(expression)
Converts a numeric expression from radians to degrees.
Return Value
The function returns 1 of the following:
-
A number representing the value in degrees.
-
NULLif the input is a non-numeric value orNULL.
Example
SELECT DEGREES(PI()/2) AS degreesValue_1,
DEGREES(PI()) AS degreesValue_2,
DEGREES(1) AS degreesValue_3,
DEGREES(NULL) AS degreesValue_4;
[
{
"degreesValue_1": 90,
"degreesValue_2": 180,
"degreesValue_3": 57.29577951308232,
"degreesValue_4": null
}
]
EXP(expression)
Returns the value of e raised to the power of the given numeric expression.
FLOOR(expression)
IMOD(expression1, expression2)
Returns the remainder of the division of 1 number by another, but returns only integer values.
| If you want the result to include both integer and floating-point numbers, use the MOD function instead. |
Arguments
- expression1
-
[Required] A valid numeric expression representing the dividend.
- expression2
-
[Required] A valid numeric expression representing the divisor.
Return Value
The function returns 1 of the following:
-
An integer representing the modulus value.
-
NULLif either dividend or divisor isNULLor non-numeric, or if the divisor is0.
Example
SELECT IMOD(10.5, 3) AS imodValue_1,
IMOD(-10, 3) AS imodValue_2,
IMOD(10, -3) AS imodValue_3,
IMOD(10, 0) AS imodValue_4,
IMOD(NULL, 3) AS imodValue_5;
[
{
"imodValue_1": 1,
"imodValue_2": -1,
"imodValue_3": 1,
"imodValue_4": null,
"imodValue_5": null
}
]
LN(expression)
Returns the natural logarithm (base e) of a numeric expression.
LOG(expression)
Returns the base 10 logarithm of a numeric expression.
MOD(expression1, expression2)
Returns the remainder of the division of 1 number by another.
| This function can return both integer and floating-point numbers. If you want the result to include only integer values, use the IMOD function instead. |
Arguments
- expression1
-
[Required] A valid numeric expression representing the dividend.
- expression2
-
[Required] A valid numeric expression representing the divisor.
NAN()
Returns the special value "NaN" (Not a Number) that represents an undefined value in numeric calculations.
POWER(expression1, expression2)
Returns the value of expression1 raised to the power of expression2.
Arguments
- expression1
-
[Required] A valid numeric expression representing the base.
- expression2
-
[Required] A valid numeric expression representing the exponent.
RADIANS(expression)
Converts a numeric expression from degrees to radians.
Return Value
The function returns 1 of the following:
-
A number representing the value in radians.
-
NULLif the input is a non-numeric value orNULL.
Example
SELECT RADIANS(90) AS radiansValue_1,
RADIANS(180) AS radiansValue_2,
RADIANS(45) AS radiansValue_3,
RADIANS(NULL) AS radiansValue_4;
[
{
"radiansValue_1": 1.5707963267948966,
"radiansValue_2": 3.141592653589793,
"radiansValue_3": 0.7853981633974483,
"radiansValue_4": null
}
]
RANDOM([ expression ])
Returns a pseudo-random number between 0 (inclusive) and 1 (exclusive).
You can optionally specify a numeric expression as a seed value. If specified, the random number generator uses this value to initialize itself. Using the same seed value always produces the same sequence of random numbers.
Example
SELECT RANDOM() AS randomValue_1,
RANDOM(42) AS randomValue_2,
RANDOM(42) AS randomValue_3,
RANDOM(100) AS randomValue_4;
[
{
"randomValue_1": 0.2427792851991457,
"randomValue_2": 0.3730283610466326,
"randomValue_3": 0.3730283610466326,
"randomValue_4": 0.8165026937796166
}
]
ROUND(expression [, digits ])
Rounds a numeric expression to the nearest integer or to a specified number of decimal places.
You can specify the number of places to round to using the optional digits parameter.
-
If
digitsis a positive integer, rounds to the specified number of places to the right of the decimal point. -
If
digitsis0or not provided, rounds to the nearest whole integer. -
If
digitsis a negative integer, rounds digits to the left of the decimal point. For example,-1rounds to the nearest 10,-2to the nearest 100, and so on.
| If you want to truncate a number without rounding, use the TRUNC function. |
Arguments
- expression
-
[Required] A valid numeric expression.
- digits
-
[Optional] An integer representing the number of decimal places to round to. The default value is
0.
SIGN(expression)
Returns the sign of a numeric expression.
The function does not return the actual sign symbol. Instead, it returns a numeric representation of the sign.
-
-1if the input value is negative. -
0if the input value is zero. -
1if the input value is positive.
SIN(expression)
SQRT(expression)
TAN(expression)
TRUNC(expression [, digits ])
Truncates a numeric expression to a specified number of decimal places. Unlike the ROUND function, this function simply removes digits without adjusting the remaining value.
You can specify the number of places to truncate to using the optional digits parameter.
-
If
digitsis a positive integer, truncates to the specified number of places to the right of the decimal point. -
If
digitsis0or not provided, truncates the expression to the nearest whole integer. -
If
digitsis a negative integer, truncates digits to the left of the decimal point. For example,-1truncates to the nearest 10,-2to the nearest 100, and so on.
Arguments
- expression
-
[Required] A valid numeric expression.
- digits
-
[Optional] An integer representing the number of decimal places to truncate to. The default value is
0.