Home > Backend Development > PHP Tutorial > MySQL查询支持正则数字吗?

MySQL查询支持正则数字吗?

WBOY
Release: 2016-06-06 20:46:53
Original
946 people have browsed it

请问大家mysql查寻如何可以通过正则来查询一个特定的数字啊?
例如我想查询字段中带有115数字的列,却想排除1115或者11555555这种,mysql支持这种查询吗?

回复内容:

请问大家mysql查寻如何可以通过正则来查询一个特定的数字啊?
例如我想查询字段中带有115数字的列,却想排除1115或者11555555这种,mysql支持这种查询吗?

对比着mysql手册写了一下, 写的很丑, 没办法, 没找到\D, (|[^0-9X])也给我报错, 唉. mysql5.5.24

<code>mysql> select '115' regexp '^115$|^115[^0-9X]|[^0-9X]115$|[^0-9X]115[^0-9X]' res
ult;
+--------+
| result |
+--------+
|      1 |
+--------+
1 row in set (0.00 sec)

mysql> select '1150' regexp '^115$|^115[^0-9X]|[^0-9X]115$|[^0-9X]115[^0-9X]' re
sult;
+--------+
| result |
+--------+
|      0 |
+--------+
1 row in set (0.00 sec)

mysql> select '11150' regexp '^115$|^115[^0-9X]|[^0-9X]115$|[^0-9X]115[^0-9X]' r
esult;
+--------+
| result |
+--------+
|      0 |
+--------+
1 row in set (0.00 sec)

mysql> select 'a115a' regexp '^115$|^115[^0-9X]|[^0-9X]115$|[^0-9X]115[^0-9X]' r
esult;
+--------+
| result |
+--------+
|      1 |
+--------+
1 row in set (0.00 sec)
</code>
Copy after login

不支持,效率太低,需要自己处理。

支持,不过效率不高。
SELECT mm,mm REGEXP '.星号[^1]115[^5].星号$' FROM test.a;

Related labels:
source:php.cn
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template