11.3.23 LOCATE(substr,str)函数
LOCATE(substr,str)函数返回字符串substr在字符串str中的位置。使用示例如下:
mysql> SELECT LOCATE('he', 'binghe');
+------------------------+
| LOCATE('he', 'binghe') |
+------------------------+
| 5 |
+------------------------+
1 row in set (0.00 sec)
注意:MySQL中,字符串的位置是从1开始的。
POSITION(substr IN str)函数作用与LOCATE(substr,str)函数相同,返回字符串substr在字符串str中的位置。使用示例如下:
mysql> SELECT POSITION('he' IN 'binghe');
+----------------------------+
| POSITION('he' IN 'binghe') |
+----------------------------+
| 5 |
+----------------------------+
1 row in set (0.00 sec)