MySQL搜索是否多个字符串包含特殊字符?
要搜索字符串是否包含特殊字符,可以使用REGEXP。以下是语法-
select * from yourTableName where yourColumnName REGEXP '[^a-zA-Z0-9]';
让我们首先创建一个表-
mysql> create table specialCharactersDemo -> ( -> StudentId varchar(100) -> );
使用insert命令在表中插入记录。以下是查询-
mysql> insert into specialCharactersDemo values('STU_1234');
mysql> insert into specialCharactersDemo values('STU567');
mysql> insert into specialCharactersDemo values('STU#1234');
mysql> insert into specialCharactersDemo values('STU897$');
mysql> insert into specialCharactersDemo values('STU999');
mysql> insert into specialCharactersDemo values('STU1010');这是用于查询字符串是否包含特殊字符的查询-
mysql> select *from specialCharactersDemo -> where StudentId REGEXP '[^a-zA-Z0-9]';
这将产生以下输出-
+-----------+ | StudentId | +-----------+ | STU_1234 | | STU#1234 | | STU897$ | +-----------+ 3 rows in set (0.02 sec)
您可以对以上结果使用其他语法。以下是查询-
mysql> select *from specialCharactersDemo -> where StudentId REGEXP'[^[:alnum:]]';
这将产生以下输出-
+-----------+ | StudentId | +-----------+ | STU_1234 | | STU#1234 | | STU897$ | +-----------+ 3 rows in set (0.05 sec)
热门推荐
10 儿子立冬祝福语简短独特
11 对当兵的祝福语简短
12 侄儿高考试祝福语简短
13 伴郎红包祝福语朋友简短
14 媳妇生日简短祝福语朋友
15 公司年会祝福语简短最好
16 元旦感恩祝福语简短大全
17 红包祝福语简短10字
18 周六早晨祝福语简短