要替换撇号,您可以使用replace()
。以下是语法-
update yourTableName set yourColumnName=replace(yourColumnName,'\'','');
让我们首先创建一个表-
mysql> create table DemoTable ( Id int NOT NULL AUTO_INCREMENT PRIMARY KEY, Sentence varchar(100) );
使用insert命令在表中插入一些记录。为句子添加了撇号-
mysql> insert into DemoTable(Sentence) values('Chris\'s Father'); mysql> insert into DemoTable(Sentence) values('Larry\'s Mother');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----+----------------+ | Id | Sentence | +----+----------------+ | 1 | Chris's Father | | 2 | Larry's Mother | +----+----------------+ 2 rows in set (0.00 sec)
以下是替换撇号的查询-
mysql> update DemoTable set Sentence=replace(Sentence,'\'',''); Rows matched: 2 Changed: 2 Warnings: 0
让我们显示表中的记录以检查撇号是否已被替换。
mysql> select *from DemoTable;
这将产生以下输出-
+----+---------------+ | Id | Sentence | +----+---------------+ | 1 | Chriss Father | | 2 | Larrys Mother | +----+---------------+ 2 rows in set (0.00 sec)