1、从左开始截取字符串
left(str, length)
说明:left(被截取字段,截取长度)
例:select left(content,200) as abstract from my_content_t
2、从右开始截取字符串
right(str, length)
说明:right(被截取字段,截取长度)
例:select right(content,200) as abstract from my_content_t
3、截取字符串
substring(str, pos)
substring(str, pos, length)
说明:substring(被截取字段,从第几位开始截取)
substring(被截取字段,从第几位开始截取,截取长度)
例:select substring(content,5) as abstract from my_content_t
select substring(content,5,200) as abstract from my_content_t
(注:如果位数是负数 如-5 则是从后倒数位数,到字符串结束或截取的长度)
4.substr
substr(string string,num start,num length);
string为字符串;
start为起始位置;
length为长度。
和 substring 一样
5、按关键字截取字符串
substring_index(str,delim,count)
说明:substring_index(被截取字段,关键字,关键字出现的次数)
例:select substring_index("blog.jb51.net","。",2) as abstract from my_content_t
结果:blog.jb51
(注:如果关键字出现的次数是负数 如-2 则是从后倒数,到字符串结束)
6、trim([{both | leading | trailing} [remstr] form] str)
将字符串 str去除 remstr 所指定的前缀或后缀,返回结果字符串。如果没有指定标识符both、leading,或trailing,则默认采用 both,即将前后缀都删除。remstr 其实是个可选参数,如果没有指定它,则删除的是空格。
7、subdate(date,day)截取时间,时间减去后面的day
8、subtime(expr1,expr2) 时分秒expr1-expr2
相关文章
mysql截取字符串的函数总结mysql c api线程函数介绍mysql 实施info 函数mysql 数值函数mysql 字符串比较函数mysql 字符串函数php 字符串 函数 将字符串分割成小块php iconv 函数 截取字符串的部分php 字符串 函数 将数字格式化成货币字符串php mysql 函数 打开一个到 mysql 服务器的连接php mysql 函数 转义一个字符串用于 mysql queryphp mysql 函数 返回指定字段的长度php mysql 函数 取得结果集中字段的数目php mysql 函数 转义 sql 语句中使用的字符串中的特殊字符,并考虑到连接的当前字符集php mysqlnd uh 函数 converts a mysql connection handle into a mysqlnd connection handlephp 字符串 函数 以千位分隔符方式格式化一个数字php 杂项 函数 将数据打包成二进制字符串php 字符串 函数 return a formatted stringphp 字符串 函数 查找字符串首次出现的位置(不区分大小写)php 字符串 函数 查找字符串的首次出现
关注编程学问公众号