数学函数
更新时间:2022-09-13
PALO 支持以下数学函数:
1.sin
2.asin
3.tan
4.atan
5.cos
6.acos
7.abs
8.bin
9.ceil
10.floor
11.conv
12.degrees
13.e
14.exp
15.mod
16.fmod
17.pmod
18.greatest
19.least
20.hex
21.unhex
22.ln
23.dlog1
24.log
25.negative
26.positive
27.pi
28.pow
29.radians
30.rand
31.round
32.sign
33.sqrt
34.truncate
SIN
Description
SQL
1sin(double a)
- 功能:返回a的正弦值
- 返回类型:double类型
Example
SQL
1mysql> select sin(1), sin(0.5 * pi());
2+--------------------+-----------------+
3| sin(1.0) | sin(0.5 * pi()) |
4+--------------------+-----------------+
5| 0.8414709848078965 | 1 |
6+--------------------+-----------------+
Keywords
Plain Text
1sin
ASIN
Description
Plain Text
1asin(double a)
- 功能: 反正弦函数,a必须在 -1 到 1 之间。
- 返回类型:double类型
Example
SQL
1mysql> select asin(0.8414709848078965), asin(2);
2+--------------------------+-----------+
3| asin(0.8414709848078965) | asin(2.0) |
4+--------------------------+-----------+
5| 1 | nan |
6+--------------------------+-----------+
Keywords
Plain Text
1asin
TAN
Description
SQL
1tan(double a)
- 功能:返回a的正切值
- 返回类型:double类型
Example
SQL
1mysql> select tan(pi()/4);
2+---------------------+
3| tan(pi() / 4.0) |
4+---------------------+
5| 0.99999999999999989 |
6+---------------------+
Keywords
Plain Text
1tan
ATAN
Description
SQL
1atan(double a)
- 功能: 反正切值函数
- 返回类型:double类型
Example
SQL
1mysql> SELECT ATAN(1.5574077246549023),ATAN(0);
2+--------------------------+---------+
3| ATAN(1.5574077246549023) | ATAN(0) |
4+--------------------------+---------+
5| 1 | 0 |
6+--------------------------+---------+
Keywords
Plain Text
1atan
COS
Description
SQL
1cos(double a)
- 功能:返回参数的余弦值
- 返回类型:double类型
Example
SQL
1mysql> select cos(1), cos(0), cos(pi());
2+---------------------+----------+-----------+
3| cos(1.0) | cos(0.0) | cos(pi()) |
4+---------------------+----------+-----------+
5| 0.54030230586813977 | 1 | -1 |
6+---------------------+----------+-----------+
Keywords
Plain Text
1cos
ACOS
Description
SQL
1acos(double a)
- 功能: 反余弦函数,a必须在 -1 到 1 之间。
- 返回类型:double类型
Example
SQL
1mysql> select acos(2), acos(1), acos(-1);
2+-----------+-----------+--------------------+
3| acos(2.0) | acos(1.0) | acos(-1.0) |
4+-----------+-----------+--------------------+
5| nan | 0 | 3.1415926535897931 |
6+-----------+-----------+--------------------+
Keywords
Plain Text
1acos
ABS
Description
SQL
1abs(numeric a)
- 功能: 返回参数的绝对值
- 返回类型:数字类型
Example
SQL
1mysql> select abs(-1.2);
2+-----------+
3| abs(-1.2) |
4+-----------+
5| 1.2 |
6+-----------+
7
8mysql> select abs(-10);
9+----------+
10| abs(-10) |
11+----------+
12| 10 |
13+----------+
Keywords
Plain Text
1abs
BIN
Description
SQL
1bin(bigint a)
- 功能: 返回整型的二进制表示形式(即0 和1 序列)
- 返回类型:string类型
Example
SQL
1mysql> select bin(10);
2+---------+
3| bin(10) |
4+---------+
5| 1010 |
6+---------+
Keywords
Plain Text
1bin
CEIL,CEILING,DCEIL
Description
SQL
1ceil(double a)
2ceiling(double a)
3dceil(double a)
- 功能: 返回大于等于该参数的最小整数
- 返回类型:int类型
Example
SQL
1mysql> select dceil(1.2), ceiling(1.2), ceil(1.2);
2+------------+--------------+-----------+
3| dceil(1.2) | ceiling(1.2) | ceil(1.2) |
4+------------+--------------+-----------+
5| 2 | 2 | 2 |
6+------------+--------------+-----------+
Keywords
Plain Text
1dceil, ceiling, ceil
FLOOR
Description
SQL
1floor(double a)
2dfloor(double a)
- 功能:返回小于等于该参数的最大整数
- 返回类型:int类型
Example
SQL
1mysql> select floor(2.9);
2+------------+
3| floor(2.9) |
4+------------+
5| 2 |
6+------------+
7
8mysql> select dfloor(2.9);
9+-------------+
10| dfloor(2.9) |
11+-------------+
12| 2 |
13+-------------+
Keywords
Plain Text
1floor, dfloor
CONV
Description
SQL
1conv(bigint num, int from_base, int to_base)
2conv(string num,int from_base, int to_base)
- 功能: 进制转换函数,返回某个整数在特定进制下的的字符串形式。输入参数可以是整型的字符串形式。如果想要将函数的返回值转换成整数,可以使用
CAST
函数。 - 返回类型:string类型
Example
SQL
1mysql> select conv(64,10,8);
2+-----------------+
3| conv(64, 10, 8) |
4+-----------------+
5| 100 |
6+-----------------+
7
8mysql> select cast(conv('fe', 16, 10) as int) as "transform_string_to_int";
9+-------------------------+
10| transform_string_to_int |
11+-------------------------+
12| 254 |
13+-------------------------+
Keywords
Plain Text
1conv
DEGREES
Description
SQL
1degrees(double a)
- 功能:将弧度转成角度
- 返回类型:double类型
Example
SQL
1mysql> select degrees(pi());
2+---------------+
3| degrees(pi()) |
4+---------------+
5| 180 |
6+---------------+
Keywords
Plain Text
1degrees
E
Description
SQL
1e()
- 功能:返回数学上的常量e
- 返回类型:double类型
Example
SQL
1mysql> select e();
2+--------------------+
3| e() |
4+--------------------+
5| 2.7182818284590451 |
6+--------------------+
Keywords
Plain Text
1e
EXP,DEXP
Description
SQL
1exp(double a)
2dexp(double a)
- 功能: 返回 e 的 a 次幂
- 返回类型: double 类型
Example
SQL
1mysql> select exp(2);
2+------------------+
3| exp(2.0) |
4+------------------+
5| 7.38905609893065 |
6+------------------+
7
8mysql> select dexp(2);
9+------------------+
10| dexp(2.0) |
11+------------------+
12| 7.38905609893065 |
13+------------------+
Keywords
Plain Text
1exp, dexp
MOD
Description
SQL
1mod(numeric_type a, same_type b)
- 功能:返回a除以b的余数。等价于%算术符。
- 返回类型:和输入类型相同
Example
SQL
1mysql> select mod(10,3);
2+------------+
3| mod(10, 3) |
4+------------+
5| 1 |
6+------------+
7
8mysql> select mod(5.5,2);
9+-------------+
10| mod(5.5, 2) |
11+-------------+
12| 1.5 |
13+-------------+
Keywords
Plain Text
1mod
FMOD
Description
SQL
1fmod(double a, double b)
2fmod(float a, float b)
- 功能:返回a除以b的余数。等价于 % 算术符
- 返回类型:float或者double类型
Example
Plain Text
1mysql> select fmod(10,3);
2+-----------------+
3| fmod(10.0, 3.0) |
4+-----------------+
5| 1 |
6+-----------------+
7
8mysql> select fmod(5.5,2);
9+----------------+
10| fmod(5.5, 2.0) |
11+----------------+
12| 1.5 |
13+----------------+
Keywords
Plain Text
1fmod
PMOD
Description
SQL
1pmod(int a, int b)
2pmod(double a, double b)
- 功能:正取余函数
- 返回类型:int类型或者double类型(由输入参数决定)
Example
SQL
1mysql> select pmod(3, 2), pmod(1.1, 2);
2+------------+------------+
3| pmod(3, 2) | pmod(1, 2) |
4+------------+------------+
5| 1 | 1 |
6+------------+------------+
Keywords
Plain Text
1pmod
GREATEST
Description
SQL
1greatest(bigint a[, bigint b ...])
2greatest(double a[, double b ...])
3greatest(decimal(p,s) a[, decimal(p,s) b ...])
4greatest(string a[, string b ...])
5greatest(timestamp a[, timestamp b ...])
- 功能:返回列表里的最大值
- 返回类型:和参数类型相同
Example
SQL
1mysql> select greatest(1,2,3);
2+-------------------+
3| greatest(1, 2, 3) |
4+-------------------+
5| 3 |
6+-------------------+
7
8mysql> select greatest("a", "b", "c");
9+-------------------------+
10| greatest('a', 'b', 'c') |
11+-------------------------+
12| c |
13+-------------------------+
Keywords
Plain Text
1greatest
LEAST
Description
SQL
1least(bigint a[, bigint b ...])
2least(double a[, double b ...])
3least(decimal(p,s) a[, decimal(p,s) b ...])
4least(string a[, string b ...])
5least(timestamp a[, timestamp b ...])
- 功能:返回列表里的最小值
- 返回类型:和参数类型相同
Example
SQL
1mysql> select least(1,2,3);
2+----------------+
3| least(1, 2, 3) |
4+----------------+
5| 1 |
6+----------------+
7
8mysql> select least("a", "b", "c");
9+----------------------+
10| least('a', 'b', 'c') |
11+----------------------+
12| a |
13+----------------------+
Keywords
Plain Text
1least
HEX
Description
SQL
1hex(bigint a)
2hex(string a)
- 功能:返回整型或字符串中各个字符的16进制表示形式。
- 返回类型:string类型
Example
SQL
1mysql> select hex('abc');
2+------------+
3| hex('abc') |
4+------------+
5| 616263 |
6+------------+
7
8mysql> select unhex(616263);
9+---------------+
10| unhex(616263) |
11+---------------+
12| abc |
13+---------------+
Keywords
Plain Text
1hex
UNHEX
Description
SQL
1unhex(string a)
- 功能:把十六进制格式的字符串转化为原来的格式
- 返回类型:string类型
Example
SQL
1mysql> select hex('abc');
2+------------+
3| hex('abc') |
4+------------+
5| 616263 |
6+------------+
7
8mysql> select unhex(616263);
9+---------------+
10| unhex(616263) |
11+---------------+
12| abc |
13+---------------+
Keywords
Plain Text
1unhex
LN
Description
SQL
1ln(double a)
- 功能:返回2的自然对数
- 返回类型:double 类型
Example
SQL
1mysql> select ln(2);
2+---------------------+
3| ln(2.0) |
4+---------------------+
5| 0.69314718055994529 |
6+---------------------+
Keywords
Plain Text
1ln
DLOG1
Description
SQL
1dlog1(double a)
- 功能:返回参数的自然对数形式
- 返回类型:double类型
Example
SQL
1mysql> select dlog1(2);
2+---------------------+
3| dlog1(2.0) |
4+---------------------+
5| 0.69314718055994529 |
6+---------------------+
Keywords
Plain Text
1dlog1
LOG,LOG10,DLOG10,LOG2
Description
SQL
1log(double base, double a)
- 功能:返回log以base为底数,以a为指数的对数值。
- 返回类型:double类型
SQL
1log10(double a)
2dlog10(double a)
- 功能:返回log以10为底数,以a为指数的对数值。
- 返回类型:double类型
SQL
1log2(double a)
- 功能:返回log以2为底数,以a为指数的对数值。
- 返回类型:double类型
Example
SQL
1mysql> select log(2, 65536);
2+-------------------+
3| log(2.0, 65536.0) |
4+-------------------+
5| 16 |
6+-------------------+
7
8mysql> select log10(2);
9+--------------------+
10| log10(2.0) |
11+--------------------+
12| 0.3010299956639812 |
13+--------------------+
14
15mysql> select dlog10(2);
16+--------------------+
17| dlog10(2.0) |
18+--------------------+
19| 0.3010299956639812 |
20+--------------------+
21
22mysql> select log2(2);
23+-----------+
24| log2(2.0) |
25+-----------+
26| 1 |
27+-----------+
Keywords
Plain Text
1log, log10, dlog, log2
NEGATIVE
Description
SQL
1negative(int a)
2negative(double a)
- 功能:将参数a的符号位取反,如果参数是负值,则返回正值
- 返回类型:根据输入参数类型返回int类型或double类型
- 使用说明:如果你需要确保所有返回值都是负值,可以使用
-abs(a)
函数。
Example
SQL
1mysql> select negative(1.0);
2+---------------+
3| negative(1.0) |
4+---------------+
5| -1 |
6+---------------+
71 row in set (0.02 sec)
8
9mysql> select negative(-1);
10+--------------+
11| negative(-1) |
12+--------------+
13| 1 |
14+--------------+
Keywords
Plain Text
1negative
POSITIVE
Description
SQL
1positive(int a)
- 功能:返回参数的原值,即使参数是负的,仍然返回原值。
- 返回类型:int类型
- 使用说明:如果你需要确保所有返回值都是正值,可以使用
abs()
函数。
Example
SQL
1mysql> select positive(-1), positive(1);
2+--------------+-------------+
3| positive(-1) | positive(1) |
4+--------------+-------------+
5| -1 | 1 |
6+--------------+-------------+
Keywords
Plain Text
1positive
PI
Description
SQL
1pi()
- 功能:返回常量Pi
- 返回类型: double类型
Example
SQL
1mysql> select pi();
2+--------------------+
3| pi() |
4+--------------------+
5| 3.1415926535897931 |
6+--------------------+
Keywords
Plain Text
1pi
POW,POWER,DPOW,FPOW
Description
SQL
1pow(double a, double p)
2power(double a, double p)
3dpow(double a, double p)
4fpow(double a, double p)
- 功能:返回a的p次幂
- 返回类型:double类型
Example
SQL
1mysql> select pow(2, 10), power(2, 10), dpow(2, 10), fpow(2, 10);
2+----------------+------------------+-----------------+-----------------+
3| pow(2.0, 10.0) | power(2.0, 10.0) | dpow(2.0, 10.0) | fpow(2.0, 10.0) |
4+----------------+------------------+-----------------+-----------------+
5| 1024 | 1024 | 1024 | 1024 |
6+----------------+------------------+-----------------+-----------------+
Keywords
Plain Text
1POW, POWER, DPOW, FPOW
RADIANS
Description
SQL
1radians(double a)
- 功能:将弧度转换成角度
- 返回类型:double类型
Example
SQL
1mysql> select radians(90);
2+--------------------+
3| radians(90.0) |
4+--------------------+
5| 1.5707963267948966 |
6+--------------------+
Keywords
Plain Text
1radians
RAND,RANDOM
Description
SQL
1rand()
2random()
- 功能:返回0~1之间的随机值。
- 返回类型:double
Example
SQL
1mysql> select rand(), rand(), random();
2+---------------------+---------------------+---------------------+
3| rand() | rand() | random() |
4+---------------------+---------------------+---------------------+
5| 0.39794450929180808 | 0.34321919244300736 | 0.38788449829415106 |
6+---------------------+---------------------+---------------------+
Keywords
Plain Text
1rand, random
ROUND
Description
SQL
1round(double a)
2round(double a, int d)
- 功能:取整函数。如果只带一个参数,该函数会返回距离该值最近的整数。如果带2个参数,第二个参数为小数点后面保留的位数。
- 返回类型:如果参数是浮点类型则返回bigint。如果第二个参数大于1,则返回double类型。
Example
SQL
1mysql> select round(100.456, 2);
2+-------------------+
3| round(100.456, 2) |
4+-------------------+
5| 100.46 |
6+-------------------+
Keywords
Plain Text
1round
SIGN
Description
SQL
1sign(double a)
- 功能:如果a是整数或者0,返回1;如果a是负数,则返回-1
- 返回类型:int类型
Example
SQL
1mysql> select sign(-1), sign(1.2);
2+------------+-----------+
3| sign(-1.0) | sign(1.2) |
4+------------+-----------+
5| -1 | 1 |
6+------------+-----------+
Keywords
Plain Text
1sign
SQRT,DSQRT
Description
SQL
1sqrt(double a)
2dsqrt(double a)
- 功能:返回a的平方根
- 返回类型:double类型
Example
SQL
1mysql> select sqrt(4), dsqrt(10);
2+-----------+--------------------+
3| sqrt(4.0) | dsqrt(10.0) |
4+-----------+--------------------+
5| 2 | 3.1622776601683795 |
6+-----------+--------------------+
Keywords
Plain Text
1sqrt, dsqrt
TRUNCATE
Description
SQL
1truncate(double num, int len)
- 功能:截取num保留len指定小数位数
- 返回类型:double类型
Example
SQL
1select truncate(1.1234, 2);
2+---------------------+
3| truncate(1.1234, 2) |
4+---------------------+
5| 1.12 |
6+---------------------+
Keywords
Plain Text
1truncate