让我们首先创建一个表-
mysql> create table DemoTable ( Title varchar(100) );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable values('\\"MySQL'); mysql> insert into DemoTable values('MongoDB\\"'); mysql> insert into DemoTable values('\\"Java\\"'); mysql> insert into DemoTable values('\\"C\"');
使用select语句显示表中的所有记录-
mysql> select *from DemoTable;
这将产生以下输出-
+-----------+ | Title | +-----------+ | \"MySQL | | MongoDB\" | | \"Java\" | | \"C" | +-----------+ 4 rows in set (0.00 sec)
以下是用前面的反斜杠字符串值替换varchar列中的反斜杠的查询-
mysql> update DemoTable set Title=replace(Title,'\\"','"'); Rows matched: 4 Changed: 4 Warnings: 0
让我们再次检查表记录-
mysql> select *from DemoTable;
这将产生以下输出-
+----------+ | Title | +----------+ | "MySQL | | MongoDB" | | "Java" | | "C" | +----------+ 4 rows in set (0.00 sec)