在MySQL字段名中添加短横线和空格?
你可以使用 REPLACE() 函数来实现。首先我们创建一个表 –
mysql> create table DemoTable1625
-> (
-> FullName varchar(20)
-> );
Query OK, 0 rows affected (0.68 sec)
使用 insert 命令向表中插入一些记录 –
mysql> insert into DemoTable1625 values('John Doe');
Query OK, 1 row affected (0.12 sec)
mysql> insert into DemoTable1625 values('Adam Smith');
Query OK, 1 row affected (0.16 sec)
mysql> insert into DemoTable1625 values('John Smith');
Query OK, 1 row affected (0.17 sec)
mysql> insert into DemoTable1625 values('Carol Taylor');
Query OK, 1 row affected (0.14 sec)
使用 select 语句显示表中的所有记录 –
mysql> select * from DemoTable1625;
输出如下 –
+--------------+
| FullName |
+--------------+
| John Doe |
| Adam Smith |
| John Smith |
| Carol Taylor |
+--------------+
4 rows in set (0.00 sec)
以下是在字段名中添加短横线的查询 –
mysql> update DemoTable1625 set FullName=replace(FullName,' ','-');
Query OK, 4 rows affected (0.15 sec)
Rows matched: 4 Changed: 4 Warnings: 0
我们再次检查表记录 –
mysql> select * from DemoTable1625;
输出如下 –
+--------------+
| FullName |
+--------------+
| John-Doe |
| Adam-Smith |
| John-Smith |
| Carol-Taylor |
+--------------+
4 rows in set (0.00 sec)
阅读更多:MySQL 教程