浅析MySQL之字符串函数


1. left函数, 对查询字段的字符串内容进行截取,用法select left(content,50) as summary from article; 在这里的意思是只查询content列内容的前50个字符,在这里汉字也只当作一个字符。

2. right函数,与left函数刚好相反,它对内容从后面进行截取。

3. upper函数,对查询的内容中的小写字母进行大写处理。select upper(title) as title from article;

4. lower函数,和upper刚好相反,它是进行小写处理。

5. substr函数,对字符串从指定位置,进行指定长度的裁剪,它比left和right更灵活。 select substr(content, 10, 50) from article, 从第10个字符(第一个字符为1不为0)开始截取50个字符;select substr(content,10)    from article,从第10个字符开始截取到末尾;select substr(content, –20) from article,从末尾起截取20个字符。


« 
» 
快速导航

Copyright © 2016 phpStudy | 豫ICP备2021030365号-3