字符串函数(String Functions)

官方文档

下面列举几个常用的函数:

  • UPPER:转大写
  • LOWER:转小写
  • CONCAT:字符串拼接
  • CONCAT_WS:字符串以指定符号拼接
  • TRIM:去除两边的空字符
  • LTRIM: 去除左边的空字符
  • RPAD:如果字符串不满足指定 字符数量,则使用指定字符串补全
  1. SELECT
  2. UPPER(m.movie_title) as title,
  3. LENGTH(m.movie_title) as len,
  4. LOWER(m.director) as dir,
  5. CONCAT('First', ' ', 'Second') as text,
  6. CONCAT_WS(' / ', m.movie_title, m.director, m.movie_id),
  7. TRIM(' trim function ') as tr,
  8. LTRIM(' trim function ') as tr,
  9. LEFT ('function ', 3) as tr,
  10. RPAD('password', 20, '*&%') as tr
  11. FROM 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