substr( string, start_position, [ length ] ) string:is the source string. start_position:is the position for extraction. The first position in the string is always 1. length:is optional. It is the number of characters to extract. If this parameter is omitted, substr will return the entire string.Note: 1.If start_position is 0, then substr treats start_position as 1 (ie: the first position in the string). [如果起始位置为0,那么substr函数将其当做1处理,也就是字符串(string)的第一个位置] 2.If start_position is a positive number, then substr starts from the beginning of the string. 3.If start_position is a negative number, then substr starts from the end of the string and counts backwards. 4.If length is a negative number, then substr will return a NULL value.For example: substr('_yeexunOnCSDN',8) char_return 'OnCSDN' substr('_yeexunOnCSDN',10) char_return 'CSDN' substr('_yeexunOnCSDN',8,2) char_return 'On' substr('_yeexunOnCSDN',-4,4) char_return 'CSDN' substr('_yeexunOnCSDN',0,7) char_return '_yeexun' substr('_yeexunOnCSDN',1,7) char_return '_yeexun' substr('_yeexunOnCSDN',0,1) char_return '_' substr('_yeexunOnCSDN',1,1) char_return '_' substr('_yeexunOnCSDN',0,2) char_return '_y' substr('_yeexunOnCSDN',1,2) char_return '_y'
而且百度上:substr(字段,a,b)
a代表第几个位置
b代表长度
0和1的效果一样
substr( string, start_position, [ length ] )
string:is the source string.
start_position:is the position for extraction. The first position in the string is always 1.
length:is optional. It is the number of characters to extract. If this parameter is omitted, substr will return the entire string.Note:
1.If start_position is 0, then substr treats start_position as 1
(ie: the first position in the string).
[如果起始位置为0,那么substr函数将其当做1处理,也就是字符串(string)的第一个位置]
2.If start_position is a positive number,
then substr starts from the beginning of the string.
3.If start_position is a negative number,
then substr starts from the end of the string and counts backwards.
4.If length is a negative number, then substr will return a NULL value.For example:
substr('_yeexunOnCSDN',8) char_return 'OnCSDN'
substr('_yeexunOnCSDN',10) char_return 'CSDN'
substr('_yeexunOnCSDN',8,2) char_return 'On'
substr('_yeexunOnCSDN',-4,4) char_return 'CSDN'
substr('_yeexunOnCSDN',0,7) char_return '_yeexun'
substr('_yeexunOnCSDN',1,7) char_return '_yeexun'
substr('_yeexunOnCSDN',0,1) char_return '_'
substr('_yeexunOnCSDN',1,1) char_return '_'
substr('_yeexunOnCSDN',0,2) char_return '_y'
substr('_yeexunOnCSDN',1,2) char_return '_y'