从 MySQL 字段中删除部分数据?
若要删除部分数据,请使用 UPDATE 命令以及 REPLACE()。让我们先创建一个表 -
mysql> create table DemoTable1583 -> ( -> GameDetails text -> ); Query OK, 0 rows affected (1.38 sec)
使用 insert 命令在表中插入一些记录 -
mysql> insert into DemoTable1583 values('<GameName>=Candy</GameName>,<GamePrice>2000</GamePrice>'); Query OK, 1 row affected (0.53 sec) mysql> insert into DemoTable1583 values('<GameName>=Lucky29</GameName>,<GamePrice>10000</GamePrice>'); Query OK, 1 row affected (0.25 sec)
使用 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>',''); Query OK, 1 row affected (0.38 sec) 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)
广告