用 MySQL SELECT 将列名转换为小写?
首先,让我们创建一个表格 −
mysql> create table DemoTable ( UserId int NOT NULL AUTO_INCREMENT PRIMARY KEY, UserFirstName varchar(20), UserLastName varchar(20), UserAge int, UserCountryName varchar(20) ); Query OK, 0 rows affected (0.27 sec)
现在检查表格的描述。
mysql> desc DemoTable;
这将产生以下输出 −
+-----------------+-------------+------+-----+---------+----------------+ | Field | Type | Null | Key | Default | Extra | +-----------------+-------------+------+-----+---------+----------------+ | UserId | int(11) | NO | PRI | NULL | auto_increment | | UserFirstName | varchar(20) | YES | | NULL | | | UserLastName | varchar(20) | YES | | NULL | | | UserAge | int(11) | YES | | NULL | | | UserCountryName | varchar(20) | YES | | NULL | | +-----------------+-------------+------+-----+---------+----------------+ 5 rows in set (0.00 sec)
以下是对使用 SELECT 将大小写转换为小写列名的查询。
mysql> SELECT LOWER(COLUMN_NAME) FROM INFORMATION_SCHEMA.COLUMNS WHERE table_name = 'DemoTable';
这将产生以下输出 −
+--------------------+ | LOWER(COLUMN_NAME) | +--------------------+ | userage | | usercountryname | | userfirstname | | userid | | userlastname | +--------------------+ 5 rows in set (0.03 sec)
广告