展示所有包含大写字母的字段的 MySQL 查询?
要展示所有包含大写字母的字段,可以使用 RLIKE,它针对模式执行字符串表达式的模式匹配。
我们首先创建一个表 -
mysql> create table contains_capital_letterDemo -> ( -> Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, -> Name varchar(100) -> ); Query OK, 0 rows affected (1.42 sec)
以下是使用插入命令在表中插入一些记录的查询 -
mysql> insert into contains_capital_letterDemo(Name) values('Larry'); Query OK, 1 row affected (0.17 sec) mysql> insert into contains_capital_letterDemo(Name) values('larry'); Query OK, 1 row affected (0.12 sec) mysql> insert into contains_capital_letterDemo(Name) values('john'); Query OK, 1 row affected (0.13 sec) mysql> insert into contains_capital_letterDemo(Name) values('JOHN'); Query OK, 1 row affected (0.36 sec) mysql> insert into contains_capital_letterDemo(Name) values('mike'); Query OK, 1 row affected (0.14 sec) mysql> insert into contains_capital_letterDemo(Name) values('Mike'); Query OK, 1 row affected (0.27 sec)
以下是使用 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)
广告