首页 > 解决方案 > 如何选择包含非 ascii 字符的列名?

问题描述

我想从具有非 ascii 字符的列名中选择值,但这是不可能的。

列名是“Descripón”,我想删除“ó”并将其转换为à ³.

如何进行选择?

标签: mysqlsql

解决方案


如果您使用分隔标识符,则可以使用特殊字符:

mysql> create table mytable ( `Descripón` text );
Query OK, 0 rows affected (0.03 sec)

mysql> insert into mytable (`Descripón`) values ('hello world');
Query OK, 1 row affected (0.01 sec)

mysql> select `Descripón` from mytable;
+--------------+
| Descripón   |
+--------------+
| hello world  |
+--------------+

如果要将列名更改为仅 ASCII 字符,以便以后可以使用它而不用分隔它:

mysql> alter table mytable change column `Descripón` Description text;
Query OK, 0 rows affected (0.02 sec)
Records: 0  Duplicates: 0  Warnings: 0

mysql> select Description from mytable;
+-------------+
| Description |
+-------------+
| hello world |
+-------------+

但是你不能像ó在 MySQL 查询中那样使用 HTML 实体,抱歉。


推荐阅读