为什么在sql中使用正则表达式会得到空结果?

产品表中有一列名为关键字。

+---------+
| keyword |
+---------+
| dump    |
| dump2   |
| dump4   |
| dump5   |
| pro     |
+---------+

I am fetching those results from product table by using regex whose keyword containing the string du anywhere.
I used select * from products where keyword LIKE '%[du]%';
but it is returning empty set.
What am I doing wrong here ?

评论
et_qui
et_qui

If you must use regex, you can just use du as the regex; that will match the string du anywhere in the keyword:

SELECT * 
FROM products
WHERE keyword REGEXP 'du'

输出:

keyword
dump
dump2
dump4
dump5

Demo on dbfiddle

点赞
评论