1.求绝对值 ,正值,负值:

ABS(numeric_type a)

POSITIVE(numeric_type a)

NEGATIVE(numeric_type a)

NEGATIVE 等同于 -abs(a)

POSITIVE 等同于 abs()

2.求余数,求商:

QUOTIENT(BIGINT numerator, BIGINT denominator), QUOTIENT(DOUBLE numerator, DOUBLE denominator)

FMOD(DOUBLE a, DOUBLE b), FMOD(FLOAT a, FLOAT b)

MOD(numeric_type a, same_type b)

PMOD(BIGINT a, BIGINT b), PMOD(DOUBLE a, DOUBLE b)

 

3.取浮点数的精度和小数点位数:

SCALE(numeric_expression)

PRECISION(numeric_expression)

4.阶乘运算

FACTORIAL(integer_type a)

阶乘函数和!符合效果一样

5.向上和向下取数

CEIL(DOUBLE a), CEIL(DECIMAL(p,s) a), CEILING(DOUBLE a), CEILING(DECIMAL(p,s) a), DCEIL(DOUBLE a), DCEIL(DECIMAL(p,s) a)

FLOOR(DOUBLE a), FLOOR(DECIMAL(p,s) a), DFLOOR(DOUBLE a), DFLOOR(DECIMAL(p,s) a)

6.常量函数pi和e

E

PI

7.求n次方 和求开方

POW(DOUBLE a, double p), POWER(DOUBLE a, DOUBLE p), DPOW(DOUBLE a, DOUBLE p), FPOW(DOUBLE a, DOUBLE p)

SQRT(DOUBLE a), DSQRT(DOUBLE a)

8.进制转换:

BIN(BIGINT a)

HEX(BIGINT a), HEX(STRING a)

UNHEX(STRING a)

CONV(BIGINT n, INT from_base, INT to_base), CONV(STRING s, INT from_base, INT to_base)

9.去最大值和最小值

GREATEST,LEAST

10.判断是否为无穷和NAN

IS_INF(DOUBLE a)

IS_NAN(DOUBLE a)

11.伪随机数:

RAND(), RAND(BIGINT seed), RANDOM(), RANDOM(BIGINT seed)

12. 分桶函数:Postgresql 9.6+ 和Oracle都支持的函数。

WIDTH_BUCKET(DECIMAL expr, DECIMAL min_value, DECIMAL max_value, INT num_buckets)

13.近视数取数:

TRUNCATE, DTRUNC, TRUNC

ROUND, DROUND

支持的数据类型:

ROUND(DOUBLE a), ROUND(DOUBLE a, INT d), ROUND(DECIMAL a, int_type d), DROUND(DOUBLE a), DROUND(DOUBLE a, INT d), DROUND(DECIMAL(p,s) a, int_type d)


TRUNCATE(DOUBLE_or_DECIMAL a[, digits_to_leave]), DTRUNC(DOUBLE_or_DECIMAL a[, digits_to_leave]), TRUNC(DOUBLE_or_DECIMAL a[, digits_to_leave])

14.HASH 函数:

FNV_HASH(type v)

MURMUR_HASH(type v)

15.LOG函数

16.正弦和余弦函数:

DEGREES(DOUBLE a)

RADIANS(DOUBLE a)

ACOS

ASIN

ATAN

ATAN2

COS

COSH

COT

SIGN

SIN

SINH

TAN

TANH

参考: