Updated on 2024-08-19 GMT+08:00

Arithmetic Functions

Table 1 Arithmetic functions

Operator

Description

+ numeric

Returns a numeric.

- numeric

Returns the opposite of a numeric.

numeric1 + numeric2

Returns the sum of numeric1 and numeric2.

numeric1 - numeric2

Returns the difference between numeric1 and numeric2.

numeric1 * numberic2

Returns the product of numeric1 and numeric2.

numeric1 / numeric2

Returns the quotient of 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)

Returns numeric1 raised to the power of 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 logarithm (base 10) of numeric.

LOG2(numeric)

Returns the logarithm (base 2) of numeric.

LOG(numeric2)

LOG(numeric1, numeric2)

When called with one argument, returns the natural logarithm of numeric2. When called with two arguments, returns the logarithm of numeric2 with base numeric1. 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 up and returns the smallest integer greater than or equal to numeric.

FLOOR(numeric)

Rounds down and returns the largest integer 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 tangent of numeric.

TAN(numeric)

Calculates the tangent of given A.

TANH(numeric)

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

COT(numeric)

Returns the cotangent of numeric.

ASIN(numeric)

Returns the inverse sine of numeric.

ACOS(numeric)

Returns the inverse cosine of numeric.

ATAN(numeric)

Returns the inverse tangent of numeric.

ATAN2(numeric1, numeric2)

Returns the inverse tangent of the coordinate (numeric1, numeric2).

COSH(numeric)

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

DEGREES(numeric)

Returns the degree representation of the radian numeric.

RADIANS(numeric)

Returns the radian representation of the degree numeric.

SIGN(numeric)

Returns the sign of numeric.

ROUND(numeric, INT)

Returns the value of numeric rounded to INT decimal places.

PI()

Returns a value very close to pi.

E()

Returns a value very close to e.

RAND()

Returns a pseudo-random double-precision value within the range of [0.0, 1.0).

RAND(INT)

Returns a pseudo-random double-precision value within the range of [0.0, 1.0) with an initial seed of INT.

If two RAND functions have the same initial seed, they will return the same sequence of numbers.

RAND_INTEGER(INT)

Returns a pseudo-random integer within the range of [0, INT).

RAND_INTEGER(INT1, INT2)

Returns a pseudo-random integer within the range of [0, INT2) with an initial seed of INT1.

If two RAND_INTEGER functions have the same initial seed and boundary, they will return the same sequence of numbers.

UUID()

Returns a universally unique identifier (UUID) string based on RFC 4122 type 4 (pseudo-random generated).

For example, 3d3c68f7-f608-473f-b60c-b0c44ad4cc4e is generated using a cryptographically strong pseudo-random number generator.

BIN(INT)

Returns the string representation of INTEGER in binary format. If INTEGER is NULL, returns NULL.

For example, 4.bin() returns "100", and 12.bin() returns "1100".

HEX(numeric)

HEX(string)

Returns the string representation of the numeric value or STRING in hexadecimal format. If the parameter is NULL, returns NULL.

For example, the number 20 returns "14", the number 100 returns "64", and the string "hello,world" returns "68656C6C6F2C776F726C64".

TRUNCATE(numeric1, integer2)

Returns the number with integer2 decimal places truncated. If numeric1 or integer2 is NULL, returns NULL.

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

This function can also be called with only one numeric1 parameter and without setting integer2.

If integer2 is not set, it defaults to 0. For example, 42.324.truncate(2) is 42.32, and 42.324.truncate() is 42.0.