MySQL存储过程详解(9)
10.+-----------------------+
11.| substring('abcd',1,2) |
12.+-----------------------+
13.| ab |
14.+-----------------------+
15.1 row in set (0.02 sec)
TRIM([[BOTH|LEADING|TRAILING] [padding] FROM]string2) //去除指定位置的指定字符
UCASE (string2 ) //转换成大写
RIGHT(string2,length) //取string2最后length个字符
SPACE(count) //生成count个空格
(2).数学类
ABS (number2 ) //绝对值
BIN (decimal_number ) //十进制转二进制
CEILING (number2 ) //向上取整
CONV(number2,from_base,to_base) //进制转换
FLOOR (number2 ) //向下取整
FORMAT (number,decimal_places ) //保留小数位数
HEX (DecimalNumber ) //转十六进制
注:HEX()中可传入字符串,则返回其ASC-11码,如HEX('DEF')返回4142143
也可以传入十进制整数,返回其十六进制编码,如HEX(25)返回19
LEAST (number , number2 [,..]) //求最小值
MOD (numerator ,denominator ) //求余
POWER (number ,power ) //求指数
RAND([seed]) //随机数
ROUND (number [,decimals ]) //四舍五入,decimals为小数位数]
注:返回类型并非均为整数,如:
(1)默认变为整形值
1. mysql> select round(1.23);
2. +-------------+
3. | round(1.23) |
4. +-------------+
5. | 1 |
6. +-------------+
7. 1 row in set (0.00 sec)
8.
9. mysql> select round(1.56);
10.+-------------+
11.| round(1.56) |
12.+-------------+
13.| 2 |
14.+-------------+
15.1 row in set (0.00 sec)
(2)可以设定小数位数,返回浮点型数据
1. mysql> select round(1.567,2);
2. +----------------+
3. | round(1.567,2) |
4. +----------------+
5. | 1.57 |
6. +----------------+
7. 1 row in set (0.00 sec)
SIGN (number2 ) //
(3).日期时间类
ADDTIME (date2,time_interval ) //将time_interval加到date2
CONVERT_TZ (datetime2 ,fromTZ ,toTZ ) //转换时区
CURRENT_DATE ( ) //当前日期
CURRENT_TIME ( ) //当前时间
CURRENT_TIMESTAMP ( ) //当前时间戳
DATE (datetime ) //返回datetime的日期部分
DATE_ADD (date2 , INTERVAL d_value d_type ) //在date2中加上日期或时间
DATE_FORMAT (datetime ,FormatCodes ) //使用formatcodes格式显示datetime
DATE_SUB (date2 , INTERVAL d_value d_type ) //在date2上减去一个时间
相关新闻>>
- 发表评论
-
- 最新评论 更多>>