使用 MySQL 如何获取单词后包含大写字符的数据库名称?
为此,使用正则表达式。语法如下 −
select * from information_schema.schemata WHERE SCHEMA_NAME REGEXP '^yourValue_+[A-Z]';
创建一些数据库 −
mysql> create database bank_APP1; Query OK, 1 row affected (0.00 sec) mysql> create database bank_APP2; Query OK, 1 row affected (0.00 sec) mysql> create database bank_APP3; Query OK, 1 row affected (0.00 sec)
以下查询用于获取单词后包含大写字符的所有数据库 −
mysql> select * from information_schema.schemata WHERE SCHEMA_NAME REGEXP '^bank_+[A-Z]';
它将产生以下结果 −
+--------------+-------------+----------------------------+------------------------+----------+ | CATALOG_NAME | SCHEMA_NAME | DEFAULT_CHARACTER_SET_NAME | DEFAULT_COLLATION_NAME | SQL_PATH | +--------------+-------------+----------------------------+------------------------+----------+ | def | bank_app1 | utf8 | utf8_unicode_ci | NULL | | def | bank_app2 | utf8 | utf8_unicode_ci | NULL | | def | bank_app3 | utf8 | utf8_unicode_ci | NULL | +--------------+-------------+----------------------------+------------------------+----------+ 3 rows in set (0.00 sec)
广告