您可以为此使用REGEXP BINARY
select *from yourTableName where yourColumnName REGEXP BINARY '[A-Z]{2}';
让我们先创建一个表
create table FindCapitalLettrsDemo -> ( -> StudentId int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> StudentFirstName varchar(20) -> );
使用insert命令在表中插入一些记录。查询如下-
insert into FindCapitalLettrsDemo(StudentFirstName) values('JOHN'); insert into FindCapitalLettrsDemo(StudentFirstName) values('Carol'); insert into FindCapitalLettrsDemo(StudentFirstName) values('bob'); insert into FindCapitalLettrsDemo(StudentFirstName) values('carol'); insert into FindCapitalLettrsDemo(StudentFirstName) values('John');
使用select语句显示表中的所有记录。查询如下-
select *from FindCapitalLettrsDemo;
以下是输出
+-----------+------------------+ | StudentId | StudentFirstName | +-----------+------------------+ | 1 | JOHN | | 2 | Carol | | 3 | bob | | 4 | carol | | 5 | John | +-----------+------------------+ 5 rows in set (0.00 sec)
这是在MySQL中查找大写字母的查询
select *from FindCapitalLettrsDemo -> where StudentFirstName REGEXP BINARY '[A-Z]{2}';
以下是输出
+-----------+------------------+ | StudentId | StudentFirstName | +-----------+------------------+ | 1 | JOHN | +-----------+------------------+ 1 row in set (0.14 sec)