数值运算
- 数值运算
- 取整函数 : round
- 指定精度取整函数 : round
- 向下取整函数 : floor
- 向上取整函数 : ceil
- 向上取整函数 : ceiling
- 取随机数函数 : rand
- 自然指数函数 : exp
- 自然对数函数: ln
- 以 10 为底对数函数 : log10
- 以 2 为底对数函数 : log2
- 对数函数 : log
- 幂运算函数 : pow
- 幂运算函数 : power
- 开平方函数 : sqrt
- 二进制函数 : bin
- 十六进制函数 : hex
- 反转十六进制函数 : unhex
- 进制转换函数 : conv
- 绝对值函数 : abs
- 正取余函数 : pmod
- 正弦函数 : sin
- 反正弦函数 : asin
- 余弦函数 : cos
- 反余弦函数 : acos
- positive 函数 : positive
- negative 函数 : negative
数值运算
- 取整函数: round
- 指定精度取整函数: round
- 向下取整函数: floor
- 向上取整函数: ceil
- 向上取整函数: ceiling
- 取随机数函数: rand
- 自然指数函数: exp
- 以10为底对数函数: log10
- 以2为底对数函数: log2
- 对数函数: log
- 幂运算函数: pow
- 幂运算函数: power
- 开平方函数: sqrt
- 二进制函数: bin
- 十六进制函数: hex
- 反转十六进制函数: unhex
- 进制转换函数: conv
- 绝对值函数: abs
- 正取余函数: pmod
- 正弦函数: sin
- 反正弦函数: asin
- 余弦函数: cos
- 反余弦函数: acos
- positive函数: positive
- negative函数: negative
取整函数 : round
- 语法: round(double a)
- 返回值: BIGINT
- 说明: 返回double类型的整数值部分 (遵循四舍五入)
- 举例:
hive> select round(3.1415926) from dual;
3
hive> select round(3.5) from dual;
4
hive> create table dual as select round(9542.158) from dual;
hive> describe dual;
_c0 bigint
指定精度取整函数 : round
- 语法: round(double a, int d)
- 返回值: DOUBLE
- 说明: 返回指定精度d的double类型
- 举例:
hive> select round(3.1415926,4) from dual;
3.1416
向下取整函数 : floor
- 语法: floor(double a)
- 返回值: BIGINT
- 说明: 返回等于或者小于该double变量的最大的整数
- 举例:
hive> select floor(3.1415926) from dual;
3
hive> select floor(25) from dual;
25
向上取整函数 : ceil
- 语法: ceil(double a)
- 返回值: BIGINT
- 说明: 返回等于或者大于该double变量的最小的整数
- 举例:
hive> select ceil(3.1415926) from dual;
4
hive> select ceil(46) from dual;
46
向上取整函数 : ceiling
- 语法: ceiling(double a)
- 返回值: BIGINT
- 说明: 与ceil功能相同
- 举例:
hive> select ceiling(3.1415926) from dual;
4
hive> select ceiling(46) from dual;
46
取随机数函数 : rand
- 语法: rand(),rand(int seed)
- 返回值: double
- 说明: 返回一个0到1范围内的随机数。如果指定种子seed,则会等到一个稳定的随机数序列
- 举例:
hive> select rand() from dual;
0.5577432776034763
自然指数函数 : exp
- 语法: exp(double a)
- 返回值: double
- 说明: 返回自然对数e的a次方
- 举例:
hive> select exp(2) from dual;
7.38905609893065
自然对数函数: ln
- 语法: ln(double a)
- 返回值: double
- 说明: 返回a的自然对数
以 10 为底对数函数 : log10
- 语法: log10(double a)
- 返回值: double
- 说明: 返回以10为底的a的对数
- 举例:
hive> select log10(100) from dual;
2.0
以 2 为底对数函数 : log2
- 语法: log2(double a)
- 返回值: double
- 说明: 返回以2为底的a的对数
- 举例:
hive> select log2(8) from dual;
3.0
对数函数 : log
- 语法: log(double base, double a)
- 返回值: double
- 说明: 返回以base为底的a的对数
- 举例:
hive> select log(4,256) from dual;
4.0
幂运算函数 : pow
- 语法: pow(double a, double p)
- 返回值: double
- 说明: 返回a的p次幂
- 举例:
hive> select pow(2,4) from dual;
16.0
幂运算函数 : power
- 语法: power(double a, double p)
- 返回值: double
- 说明: 返回a的p次幂,与pow功能相同
- 举例:
hive> select power(2,4) from dual;
16.0
开平方函数 : sqrt
- 语法: sqrt(double a)
- 返回值: double
- 说明: 返回a的平方根
- 举例:
hive> select sqrt(16) from dual;
4.0
二进制函数 : bin
- 语法: bin(BIGINT a)
- 返回值: string
- 说明: 返回a的二进制代码表示
- 举例:
hive> select bin(7) from dual;
111
十六进制函数 : hex
- 语法: hex(BIGINT a)
- 返回值: string
- 说明: 如果变量是int类型,那么返回a的十六进制表示;如果变量是string类型,则返回该字符串的十六进制表示
- 举例:
hive> select hex(17) from dual;
11
hive> select hex(‘abc’) from dual;
616263
反转十六进制函数 : unhex
- 语法: unhex(string a)
- 返回值: string
- 说明: 返回该十六进制字符串所代码的字符串
- 举例:
hive> select unhex(‘616263’) from dual;
abc
hive> select unhex(‘11’) from dual;
-
hive> select unhex(616263) from dual;
abc
进制转换函数 : conv
- 语法: conv(BIGINT num, int from_base, int to_base)
- 返回值: string
- 说明: 将数值num从from_base进制转化到to_base进制
- 举例:
hive> select conv(17,10,16) from dual;
11
hive> select conv(17,10,2) from dual;
10001
绝对值函数 : abs
- 语法: abs(double a) abs(int a)
- 返回值: double int
- 说明: 返回数值a的绝对值
- 举例:
hive> select abs(-3.9) from dual;
3.9
hive> select abs(10.9) from dual;
10.9
正取余函数 : pmod
- 语法: pmod(int a, int b),pmod(double a, double b)
- 返回值: int double
- 说明: 返回正的a除以b的余数
- 举例:
hive> select pmod(9,4) from dual;
1
hive> select pmod(-9,4) from dual;
3
正弦函数 : sin
- 语法: sin(double a)
- 返回值: double
- 说明: 返回a的正弦值
- 举例:
hive> select sin(0.8) from dual;
0.7173560908995228
反正弦函数 : asin
- 语法: asin(double a)
- 返回值: double
- 说明: 返回a的反正弦值
- 举例:
hive> select asin(0.7173560908995228) from dual;
0.8
余弦函数 : cos
- 语法: cos(double a)
- 返回值: double
- 说明: 返回a的余弦值
- 举例:
hive> select cos(0.9) from dual;
0.6216099682706644
反余弦函数 : acos
- 语法: acos(double a)
- 返回值: double
- 说明: 返回a的反余弦值
- 举例:
hive> select acos(0.6216099682706644) from dual;
0.9
positive 函数 : positive
- 语法: positive(int a), positive(double a)
- 返回值: int double
- 说明: 返回a
- 举例:
hive> select positive(-10) from dual;
-10
hive> select positive(12) from dual;
12
negative 函数 : negative
- 语法: negative(int a), negative(double a)
- 返回值: int double
- 说明: 返回-a
- 举例:
hive> select negative(-5) from dual;
5
hive> select negative(8) from dual;
-8