要显示所有包含大写字母的字段,请使用RLIKE对字符串表达式执行模式匹配。
让我们首先创建一个表-
mysql> create table contains_capital_letterDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(100) -> );
以下是使用insert命令在表中插入一些记录的查询-
mysql> insert into contains_capital_letterDemo(Name) values('Larry'); mysql> insert into contains_capital_letterDemo(Name) values('larry'); mysql> insert into contains_capital_letterDemo(Name) values('john'); mysql> insert into contains_capital_letterDemo(Name) values('JOHN'); mysql> insert into contains_capital_letterDemo(Name) values('mike'); mysql> insert into contains_capital_letterDemo(Name) values('Mike');
以下是使用select语句显示表中所有记录的查询-
mysql> select * from contains_capital_letterDemo;
这将产生以下输出-
+----+-------+ | Id | Name | +----+-------+ | 1 | Larry | | 2 | larry | | 3 | john | | 4 | JOHN | | 5 | mike | | 6 | Mike | +----+-------+ 6 rows in set (0.00 sec)
以下是显示所有包含大写字母的字段的查询-
mysql> select * from contains_capital_letterDemo WHERE CAST(Name AS BINARY) RLIKE '[A-Z]';
这将产生以下输出-
+----+-------+ | Id | Name | +----+-------+ | 1 | Larry | | 4 | JOHN | | 6 | Mike | +----+-------+ 3 rows in set (0.00 sec)