核心差異:
LIKE:整個欄位值必須符合模式 (全匹配)REGEXP:欄位值任意部分符合即可 (部分匹配)官方文件定義:
A REGEXP pattern match succeeds if the pattern matches anywhere in the value being tested. (This differs from a LIKE pattern match, which succeeds only if the pattern matches the entire value.)
| 欄位值 | 模式 | LIKE 結果 | REGEXP 結果 |
|---|---|---|---|
'abcdef' | 'bcd' | 不匹配 | 匹配 |
'abcdef' | '^bcd' | 不匹配 | 不匹配 |
'abcdef' | 'abcdef' | 匹配 | 匹配 |
LIKE 'prefix%' 可用索引 (範圍掃描)LIKE '%suffix' / REGEXP 多導致全表掃描