How to use locate and position functions in Mysql _mysql
Source: Internet
Author: User
LOCATE (SUBSTR,STR)
POSITION (substr in str)
Returns the position of the substring substr the first occurrence in string str. If substring substr does not exist in STR, the return value is 0:
mysql> SELECT LOCATE (' Bar ', ' Foobarbar ');
-> 4
mysql> SELECT LOCATE (' Xbar ', ' foobar ');
-> 0
This function is multibyte-safe. In MySQL 3.23, this function is case-sensitive, and when in MySQL 4.0, if any argument is a binary string, it is case-sensitive.
LOCATE (Substr,str,pos)
Returns the position of the substring substr the first occurrence after the POS position in string str. If SUBSTR does not return 0 in str:
mysql> SELECT LOCATE (' Bar ', ' Foobarbar ', 5);
-> 7
This function is multibyte-safe. In MySQL 3.23, this function is case-sensitive, and when in MySQL 4.0, if any argument is a binary string, it is case-sensitive.
A typical example is:
Slect * FROM TableName where LOCATE (colum1,colum1,1) >0
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.