# 在字符串中查找字符串

__*INSTR 函数*__
__*LOCATE 函数*__
__*POSITION 函数*__

+ `INSTR(), LOCATE(), POSITION()`: 返回指定字符串在另一个字符串中的位置
  + 例如:`select instr('TiDB','DB'), instr('TiDB','D'), locate('DB', 'TiDB'), position('DB' in 'TiDB');` 
+ `LOCATE(searchstr, str, pos)`: 其中 pos 指定搜索的起始位置:
  + 例如:`select locate('DB', 'TiDB is a NewSQL style DB', 7);` 
```
tidb> SELECT instr('TiDB','DB'), instr('TiDB','D'), locate('DB', 'TiDB'), position('DB' in 'TiDB');
+--------------------+-------------------+----------------------+--------------------------+
| instr('TiDB','DB') | instr('TiDB','D') | locate('DB', 'TiDB') | position('DB' in 'TiDB') |
+--------------------+-------------------+----------------------+--------------------------+
|                  3 |                 3 |                    3 |                        3 |
+--------------------+-------------------+----------------------+--------------------------+
1 row in set (0.00 sec)
tidb> SELECT locate('~!@DB@!~', 'TiDB is a NewSQL style DB', 7);
+----------------------------------------------+
| locate('DB', 'TiDB is a NewSQL style DB', 7) |
+----------------------------------------------+
|                                           ~!@24@!~ |
+----------------------------------------------+
1 row in set (0.00 sec)
```
---------------------------------------------------------------
- `INSTR()`	返回第一次出现的子字符串的索引
- `LOCATE()/POSITION()`	返回第一次出现的子字符串的位置
