Arithmetic functions

SQL Function Description

=+ numeric

Returns numeric.

- numeric

Returns negative numeric.

numeric1 + numeric2

Returns numeric1 plus numeric2.

numeric1 - numeric2

Return numeric1 minus numeric2

numeric1 * numeric2

Returns numeric1 multiplied by numeric2

numeric1 / numeric2

Returns numeric1 divided by numeric2

numeric1 % numeric2

Returns the remainder (modulus) of numeric1 divided by numeric2. The result is negative only if numeric1 is negative.

POWER(numeric1, numeric2)

numeric1^numeric2

ABS(numeric)

Returns the absolute value of numeric.

SQRT(numeric)

Returns the square root of numeric.

LN(numeric)

Returns the natural logarithm (base e) of numeric.

LOG10(numeric)

Returns the base 10 logarithm of numeric.

LOG2(numeric)

Returns the base 2 logarithm of numeric.

LOG(numeric2)

LOG(numeric1, numeric2)

When called with one argument, returns the natural logarithm of numeric2. When called with two arguments, this function returns the logarithm of numeric2 to the base numeric1. Currently, numeric2 must be greater than 0 and numeric1 must be greater than 1.

EXP(numeric)

Returns e raised to the power of numeric.

CEIL(numeric)

CEILING(numeric)

Rounds numeric up, and returns the smallest number that’s greater than or equal to numeric.

FLOOR(numeric)

Rounds numeric down, and returns the largest number that’s less than or equal to numeric.

SIN(numeric)

Returns the sine of numeric.

SINH(numeric)

Returns the hyperbolic sine of numeric. The return type is DOUBLE.

COS(numeric)

Returns the cosine of numeric.

TAN(numeric)

Returns the tangent of numeric.

TANH(numeric)

Returns the hyperbolic tangent of numeric. The return type is DOUBLE.

COT(numeric)

Returns the cotangent of a numeric.

ASIN(numeric)

Returns the arc sine of numeric.

ACOS(numeric)

Returns the arc cosine of numeric.

ATAN(numeric)

Returns the arc tangent of numeric.

ATAN2(numeric1, numeric2)

Returns the arc tangent of a coordinate (numeric1, numeric2).

COSH(numeric)

Returns the hyperbolic cosine of numeric. Return value type is DOUBLE.

DEGREES(numeric)

Returns the degree representation of a radian numeric.

RADIANS(numeric)

Returns the radian representation of a degree numeric.

SIGN(numeric)

Returns the sign of numeric.

ROUND(numeric, int)

Returns a number rounded to int decimal places for numeric.

PI()

Returns a value that’s closer than any other values to pi.

E()

Returns a value that’s closer than any other values to e.

RAND()

Returns a pseudo-random double value in the range [0.0, 1.0)

RAND(int)

Returns a pseudo-random double value in the range [0.0, 1.0) with an initial seed integer. Two RAND functions will return identical sequences of numbers if they have the same initial seed.

RAND_INTEGER(int)

Returns a pseudo-random double value in the range [0.0, int)

RAND_INTEGER(int1, int2)

Returns a pseudo-random double value in the range [0.0, int2) with an initial seed int1. Two RAND_INTEGER functions will return identical sequences of numbers if they have the same initial seed and bound.

UUID()

Returns an UUID (Universally Unique Identifier) string (For example: “3c3c68f7-f608-473f-b60c-b0c44ad4cc4e”) according to RFC 4122 type 4 (pseudo-randomly generated) UUID. The UUID is generated using a cryptographically strong pseudo random number generator.

BIN(int)

Returns a string representation of INTEGER in binary format. Returns NULL if int is NULL. For example: 4.bin() returns "100" and 12.bin() returns "1100."

HEX(numeric)

HEX(string)

Returns a string representation of an integer numeric value or a STRING in hexadecimal format. Returns NULL if the argument is NULL.

For example:

  • a numeric 20 leads to 14

  • a numeric 100 leads to 64

  • a string hello,world leads to 68656C6C6F2C776F726C64.

TRUNCATE(numeric1, integer2)

Returns a numeric of truncated to integer2 decimal places. Returns NULL if numeric1 or integer2 is NULL.

If integer2 is 0, the result has no decimal point or fractional part. integer2 can be negative to cause integer2 digits left of the decimal point of the value to become zero.

This function can also pass in only one numeric1 parameter and not set integer2 to use. If integer2 isn’t set, the function truncates as if integer2 were 0.

For example:

  • TRUNCATE(42.324,2) returns 42.34

  • TRUNCATE(42.324) returns 42.0