要删除部分数据,请与一起使用UPDATE命令REPLACE()
。让我们首先创建一个表-
mysql> create table DemoTable1583 -> ( -> GameDetails text -> );
使用插入命令在表中插入一些记录-
mysql> insert into DemoTable1583 values('<GameName>=Candy</GameName>,<GamePrice>2000</GamePrice>'); mysql> insert into DemoTable1583 values('<GameName>=Lucky29</GameName>,<GamePrice>10000</GamePrice>');
使用select语句显示表中的所有记录-
mysql> select * from DemoTable1583;
这将产生以下输出-
+------------------------------------------------------------+ | GameDetails | +------------------------------------------------------------+ | <GameName>=Candy</GameName>,<GamePrice>2000</GamePrice> | | <GameName>=Lucky29</GameName>,<GamePrice>10000</GamePrice> | +------------------------------------------------------------+ 2 rows in set (0.00 sec)
这是从MySQL的字段中删除部分数据的查询-
mysql> update DemoTable1583 set GameDetails=replace(GameDetails,'<GameName>=Candy</GameName>',''); Rows matched: 2 Changed: 1 Warnings: 0
让我们再次检查表记录-
mysql> select * from DemoTable1583;
这将产生以下输出-
+------------------------------------------------------------+ | GameDetails | +------------------------------------------------------------+ | ,<GamePrice>2000</GamePrice> | | <GameName>=Lucky29</GameName>,<GamePrice>10000</GamePrice> | +------------------------------------------------------------+ 2 rows in set (0.00 sec)