为了从值中删除部分文本,可以REPLACE()
在MySQL中使用。以下是语法-
update yourTableName set yourColumnName = replace(yourColumnName ,'yourValue ', '' );
让我们首先创建一个表-
mysql> create table removePartialTextDemo -> ( -> JavaVersionDetails varchar(100) -> );
以下是使用insert命令在表中插入一些记录的查询-
mysql> insert into removePartialTextDemo values('Java Version 1.0'); mysql> insert into removePartialTextDemo values('Java Version 1.1'); mysql> insert into removePartialTextDemo values('Java Version 1.2'); mysql> insert into removePartialTextDemo values('Java Version 1.3'); mysql> insert into removePartialTextDemo values('Java Version 1.4'); mysql> insert into removePartialTextDemo values('Java Version 7');
以下是使用select语句显示表中所有记录的查询-
mysql> select * from removePartialTextDemo;
这将产生以下输出-
+--------------------+ | JavaVersionDetails | +--------------------+ | Java Version 1.0 | | Java Version 1.1 | | Java Version 1.2 | | Java Version 1.3 | | Java Version 1.4 | | Java Version 7 | +--------------------+ 6 rows in set (0.00 sec)
这是从值中删除部分文本的查询。我们在这里分隔版本号-
mysql> update removePartialTextDemo set JavaVersionDetails = replace(JavaVersionDetails,'Java Version ',''); Rows matched: 6 Changed: 6 Warnings: 0
让我们显示表中的所有记录以检查部分文本是否已删除-
mysql> select * from removePartialTextDemo;
这将产生以下输出-
+--------------------+ | JavaVersionDetails | +--------------------+ | 1.0 | | 1.1 | | 1.2 | | 1.3 | | 1.4 | | 7 | +--------------------+ 6 rows in set (0.00 sec)