ABS:求绝对值
CBRT:求立方根
CEILING/CEIL:向上取整
DEGREES:把弧度转化为度
E:求自然对数
EXP:返回x的自然常数次幂
FLOOR:向下取整
FROM_BASE:返回radix进制的字符串string代表的数
LN:求自然对数
LOG2:求以2为底的对数
LOG10:求以10位底的对数
LOG:返回x以b为底的对数
MOD:求余
PI:返回pi
POWER/POW:返回x的p次幂
RADIANS:将角度x以度为单位转换为弧度
RANDOM/RAND:随机函数
ROUND:返回x四舍五入后的最近的整数值,或者返回x四舍五入到d位小数位的值
SIGN:返回参数X的正负符号,结果可能为-1、0或者1
SQRT:求平方根
TO_BASE:返回x的radix进制表示的字符串
TRUNCATE:截断函数
WIDTH_BUCKET:返回x在区间(最小值为bound1,最大值为bound2)中n等分以后,所在区间的数值
ACOS:求反余弦函数值
ASIN:求反正弦函数值
ATAN:求反正切函数值
ATAN2:参数1除参数2后的反正切值
COS:求余弦
COSH:求双曲余弦
SIN:求正弦值
TAN:求正切
TANH:求双曲正切
COT:求余切函数
INFINITY:返回表示正无穷大的常量
IS_FINITE:判定x是否有限
IS_INFINITE:判定x是否无限
IS_NAN:判定x是非法数值
NAN:返回代表非数值的常量值
CRC32:计算循环冗余校验值,返回一个32位的无符号数值。参数为NULL,则返回结果为NULL
REMAINDER:返回两个参数相除的余数
BITAND:返回两个数值型数据按位进行AND运算后的结果
说明:所有三角函数都是以弧度表示。
ABS
命令说明:求绝对值
返回值类型:与输入值类型相同
示例:
select abs(-9); +-------------+ | _col0 | +-------------+ | 9 |
CBRT
cbrt(double)
命令说明:求立方根
返回值类型:DOUBLE
示例:
select cbrt(8); +-------+ | _col0 | +-------+ | 2.0 |
CEILING/CEIL
ceiling(x)
命令说明:向上取整
返回值类型:LONG
示例:
select ceiling(2.3); +-------+ | _col0 | +-------+ | 3 |
DEGREES
degrees(double)
命令说明:把弧度转化为度
返回值类型:DOUBLE
示例:
select degrees(1.3); +-------------------+ | _col0 | +-------------------+ | 74.48451336700703 |
E
e();
命令说明:求自然对数
返回值类型:DOUBLE
示例:
select e(); +-------------------+ | _col0 | +-------------------+ | 2.718281828459045 |
EXP
exp(x);
命令说明:返回x的自然常数次幂
返回值类型:DOUBLE
示例:
select exp(2); +-------------------+ | _col0 | +-------------------+ | 7.38905609893065 |
FLOOR
floor(int)
floor(bigint)
floor(double)
命令说明:向下取整
返回值类型:LONG
示例:
select floor(7.8); +-------+ | _col0 | +-------+ | 7 |
FROM_BASE
from_base(string, radix);
命令说明:返回radix进制的字符串string代表的数
返回值类型:BIGINT
示例:
SELECT from_base('0110', 2); +-------+ | _col0 | +-------+ | 6 | SELECT from_base('0110', 8); +-------+ | 72 | SELECT from_base('00a0', 16); +-------+ | _col0 | +-------+ | 160|
LN
ln(double)
命令说明:求自然对数
返回值类型:DOUBLE
示例:
select ln(2.718281828459045); +-------+ | _col0 | +-------+ | 1.0 |
LOG2
log2(double)
命令说明:求以2为底的对数
返回值类型:DOUBLE
示例:
select log2(8); +-------+ | _col0 | +-------+ | 3.0 |
LOG10
log10(double)
命令说明:求以10位底的对数
返回值类型:DOUBLE
示例:
select log10(100); +-------+ | _col0 | +-------+ | 2.0 |
LOG
log(x, b)
命令说明:返回x以b为底的对数
返回值类型:DOUBLE
示例:
select log(10,100); +-------+ | _col0 | +-------+ | 2.0 |
MOD
命令说明:求余
示例:
SELECT mod(cast(4.5 as tinyint), 3); +-------+ | _col0 | +-------+ | 2 | SELECT mod(cast(4.5 as smallint), 3); +-------+ | _col0 | +-------+ | 2 | SELECT mod(cast(4.5 as int), 3); +-------+ | _col0 | +-------+ | 2 | SELECT mod(cast(4.5 as bigint), 3); +-------+ | _col0 | +-------+ | 2 | SELECT mod(cast(4.5 as double), 3); +-------+ | _col0 | +-------+ | 1.5 |
PI
pi()
命令说明:返回pi
返回值类型:DOUBLE
示例:
select pi(); +-------------------+ | _col0 | +-------------------+ | 3.141592653589793 |
POWER/POW
power(x, p)
命令说明:返回x的p次幂
返回值类型:DOUBLE
示例:
select power(1.2,3.4); +-------------------+ | _col0 | +-------------------+ | 1.858729691979481 |
RADIANS
radians(x)
命令说明:将角度x以度为单位转换为弧度
返回值类型:DOUBLE
示例:
select radians(60.0); +--------------------+ | _col0 | +--------------------+ | 1.0471975511965976 |
RANDOM/RAND
random()
random(n)
命令说明:随机函数
返回值类型:DOUBLE
示例:
select random(); +--------------------+ | _col0 | +--------------------+ | 0.5709993917553757 | select random(cast(3 as tinyint)); +--------------------+ | _col0 | +--------------------+ | 2 | select random(cast(3 as smallint)); +--------------------+ | _col0 | +--------------------+ | 1 | select random(cast(3 as int)); +--------------------+ | _col0 | +--------------------+ | 1 | select random(cast(3 as bigint)); +--------------------+ | _col0 | +--------------------+ | 1 |
ROUND
round(x)
round(x, d)
命令说明:返回x四舍五入后的最近的整数值,或者返回x四舍五入到d位小数位的值
返回值类型:BIGINT或DOUBLE
示例:
SELECT round(cast(4.5 as tinyint), 3); +-------+ | _col0 | +-------+ | 5 | SELECT round(cast(4.5 as smallint), 3); +-------+ | _col0 | +-------+ | 5 | SELECT round(cast(4.5 as int), 3); +-------+ | _col0 | +-------+ | 5 | SELECT round(cast(4.5 as bigint), 3); +-------+ | _col0 | +-------+ | 5 | SELECT round(cast(4.5 as double), 3); +-------+ | _col0 | +-------+ | 4.5 | SELECT round(cast(4.5 as tinyint)); +-------+ | _col0 | +-------+ | 5 | SELECT round(cast(4.5 as smallint)); +-------+ | _col0 | +-------+ | 5 | SELECT round(cast(4.5 as double)); +-------+ | _col0 | +-------+ | 5.0 |
SIGN
sign(x)
命令说明:返回参数X的正负符号,结果可能为-1、0或者1
示例:
SELECT sign(0); +-------+ | _col0 | +-------+ | 0 | SELECT sign(34); +-------+ | _col0 | +-------+ | 1 | SELECT sign(-23); +-------+ | _col0 | +-------+ | -1 | SELECT sign(1.023); +-------+ | _col0 | +-------+ | 1.0 | SELECT sign(-1.023); +-------+ | _col0 | +-------+ | -1 |
SQRT
sqrt(double)
命令说明:求平方根
返回值类型:DOUBLE
示例:
select sqrt(4); +-------+ | _col0 | +-------+ | 2.0 |
TO_BASE
to_base(x, radix)
命令说明:返回x的radix进制表示的字符串
返回值类型:VARCHAR
示例:
SELECT to_base(8,8); +-------+ | _col0 | +-------+ | 10 |
TRUNCATE
truncate(double)
命令说明:截断函数
返回值类型:DOUBLE
示例:
select truncate(2.3); +-------+ | _col0 | +-------+ | 2.0 | select truncate(2.3456,2); +--------+ | _col0 | +--------+ | 2.3400 | SELECT truncate(cast(4.5 as tinyint), 3); +-------+ | _col0 | +-------+ | 5 | SELECT truncate(cast(4.5 as smallint), 3); +-------+ | _col0 | +-------+ | 5 | SELECT truncate(cast(4.5 as int), 3); +-------+ | _col0 | +-------+ | 5 | SELECT truncate(cast(4.5 as bigint), 3); +-------+ | _col0 | +-------+ | 5 |
WIDTH_BUCKET
width_bucket(x, bound1, bound2, n);
命令说明:返回x在区间(最小值为bound1,最大值为bound2)中n等分以后,所在区间的数值
返回值类型:BIGINT
示例:
SELECT WIDTH_BUCKET(5,3,4,5); +--------------------+ | _col0 | +--------------------+ | 6 |
三角函数
所有三角函数都是以弧度表示,单位转换请参见《DEGREES》、《RADIANS》。
ACOS
acos(double)
命令说明:求反余弦函数值
返回值类型:DOUBLE
示例:
select acos(0.5); +--------------------+ | _col0 | +--------------------+ | 1.0471975511965979 |
ASIN
asin(double)
命令说明:求反正弦函数值
返回值类型:DOUBLE
示例:
select asin(0.5); +--------------------+ | _col0 | +--------------------+ | 0.5235987755982989 |
ATAN
atan(double)
命令说明:求反正切函数值
返回值类型:DOUBLE
示例:
select atan(0.5); +--------------------+ | _col0 | +--------------------+ | 0.4636476090008061 |
ATAN2
atan2(double, double)
命令说明:参数1除参数2后的反正切值
返回值类型:DOUBLE
示例:
select atan2(0.5,0.3); +--------------------+ | _col0 | +--------------------+ | 1.0303768265243125 |
COS
cos(double)
命令说明:求余弦
返回值类型:DOUBLE
示例:
select cos(1.3); +---------------------+ | _col0 | +---------------------+ | 0.26749882862458735 |
COSH
cosh(double)
命令说明:求双曲余弦
返回值类型:DOUBLE
示例:
select cosh(1.3); +--------------------+ | _col0 | +--------------------+ | 1.9709142303266285 |
SIN
sin(x);
命令说明:求正弦值
返回值类型:DOUBLE
示例:
select sin(1.3); +--------------------+ | _col0 | +--------------------+ | 0.963558185417193 |
TAN
tan(double)
命令说明:求正切
返回值类型:DOUBLE
示例:
select tan(8); +--------------------+ | _col0 | +--------------------+ | -6.799711455220379 |
TANH
tanh(double)
命令说明:求双曲正切
返回值类型:DOUBLE
示例:
select tanh(8); +--------------------+ | _col0 | +--------------------+ | 0.9999997749296758 |
COT
cot(x);
命令说明:求余切函数
返回值类型:DOUBLE
示例:
SELECT COT(12); +--------------------+ | _col0 | +--------------------+ | 1.5726734063976893 |
INFINITY
命令说明:返回表示正无穷大的常量
返回值类型:DOUBLE
IS_FINITE
命令说明:判定x是否有限
返回值类型:BOOLEAN
IS_INFINITE
命令说明:判定x是否无限
返回值类型:BOOLEAN
IS_NAN
命令说明:判定x是非法数值
返回值类型:BOOLEAN
NAN
命令说明:返回代表非数值的常量值
返回值类型:DOUBLE
CRC32
CRC32(expr);
命令说明:计算循环冗余校验值,返回一个32位的无符号数值。参数为NULL,则返回结果为NULL
返回值类型:DOUBLE
示例:
SELECT CRC32('MySQL'); +--------------------+ | _col0 | +--------------------+ | 3259397556 | SELECT CRC32('mysql'); +--------------------+ | _col0 | +--------------------+ | 2501908538 |
REMAINDER
REMAINDER(n1, n2);
命令说明:返回两个参数相除的余数
返回值类型:DOUBLE/BIGINT
示例:
SELECT REMAINDER(3.5, 2); +--------------------+ | _col0 | +--------------------+ | -1.5 | SELECT REMAINDER(11, 4); +--------------------+ | _col0 | +--------------------+ | 4 |
BITAND
BITAND(expr1, expr2);
命令说明:返回两个数值型数据按位进行AND运算后的结果
如果函数中任一参数为非整数型,则在按位进行AND运算之前,需要先将参数转换为整数型
返回值类型:BIGINT
示例:
SELECT BITAND(5, 6); +--------------------+ | _col0 | +--------------------+ | 4 | SELECT BITAND(cast(5.3 as int),cast(6.2 as int)); +--------------------+ | _col0 | +--------------------+ |4 |