mysql function to intercept string

1. LEFT(str,len)

  Intercept from the left, str: the string to be intercepted; len: the length of the interception

	select left('www.baidu.com', 3);
	# www

2. RIGHT(str,len)

  Intercept from the right, str: the string to be intercepted; len: the length of the interception

	select right('www.baidu.com', 3);
	# com

3. SUBSTR(str, pos, len)

  str: the string to be intercepted; pos: the starting position of the interception; len: the length of the interception (optional: leave blank to intercept to the maximum length)

	select substr('www.baidu.com', 3);
	# w.baidu.com

4. SUBSTRING(str, pos, len)

  str: the string to be intercepted; pos: the starting position of the interception; len: the length of the interception (optional: leave blank to intercept to the maximum length)

	select substring('www.baidu.com', 3);
	# w.baidu.com

5. SUBSTRING_INDEX(str, delim, count)

  str: the string to be intercepted; delim: the character of the intercepted data base; count: the intercepted quantity (count>0, start from the left, count<0, start from the right)

	select substring_index('www.baidu.com', '.', 1);
	# www
	select substring_index('www.baidu.com', '.', -1);
	# com

6. LOCATE(substr,str)

  substr: search character; str: string; get the position of substr character from str string (not found return 0)

	select LOCATE('www', 'www.baidu.com');
	# 1
	select LOCATE('cn', 'www.baidu.com');
	# 0

Guess you like

Origin blog.csdn.net/bai_mi_student/article/details/130603150