字符串函数(String Functions)
下面列举几个常用的函数:
- UPPER:转大写
- LOWER:转小写
- CONCAT:字符串拼接
- CONCAT_WS:字符串以指定符号拼接
- TRIM:去除两边的空字符
- LTRIM: 去除左边的空字符
- RPAD:如果字符串不满足指定 字符数量,则使用指定字符串补全
SELECTUPPER(m.movie_title) as title,LENGTH(m.movie_title) as len,LOWER(m.director) as dir,CONCAT('First', ' ', 'Second') as text,CONCAT_WS(' / ', m.movie_title, m.director, m.movie_id),TRIM(' trim function ') as tr,LTRIM(' trim function ') as tr,LEFT ('function ', 3) as tr,RPAD('password', 20, '*&%') as trFROM movies m limit 1;
执行后结果:
| title | len | dir | text | text2 | tr | tr | tr | tr |
|---|---|---|---|---|---|---|---|---|
| LABYRINTH | 9 | jim henson | First Second | Labyrinth / Jim Henson / 1 | trim function | trim function | fun | password&%&%&%&% |
数字函数(Numeric Functions)
下面列举几个常用的函数:
- RAND: 生产0-1的随机数字
- ROUND:四舍五入
- FLOOR:向下取整
- CEIL:向上取整
- RADIANS:计数弧度
- DEGREES:计算角度
- POW / POWER:乘方
| degrees(角度) | radians(弧度) |
|---|---|
| 90.0 | 3.141592653589793 |
