
练习截取字符串函数(五个)
mysql索引从1开始
一、mysql截取字符串函数
1、left(str,length) 从左边截取length
2、right(str,length)从右边截取length
3、substring(str,index)当index>0从左边开始截取直到结束 当index<0从右边开始截取直到结束
当index=0返回空
4、substring(str,index,len) 截取str,从index开始,截取len长度
5、substring_index(str,delim,count),str是要截取的字符串,delim是截取的字段count是从哪里开始截取(为0则是左边第0个开始,1位左边开始第一个选取左边的,-1从右边第一个开始选取右边的
6、subdate(date,day)截取时间,时间减去后面的day
7、subtime(expr1,expr2) 时分秒expr1-expr2
二、mysql截取字符串的一些栗子
1、left(str,length) length>=0 从左边开始截取

2、right(str,length) length>=0 从右边开始截取

3、substring(str,index) =SUBSTRING(str FROM pos) 包括index这个位置的字符

4、substring(str,index,len) 截取str,从index开始,截取len长度

5、substring_index(str,delim,count),str是要截取的字符串,delim是截取的字段count是从哪里开始截取(为0则是左边第0个开始,1位左边开始第一个选取左边的,-1从右边第一个开始选取右边的

为1,从左边开始数第一个截取,选取左边的值

为-1,从右边开始数第一个截取,选取右边的值

特殊情况,字符串中没有指定的字符,则返回原字符串(index=0时候例外)

6、subdate(date,day)截取时间,时间减去后面的day

7、subtime(expr1,expr2)–是两个时间相减

网友评论