MySQL查询替换点之前的字符串的一部分
为此,请CONCAT()
与SUBSTRING_INDEX()一起使用。让我们首先创建一个-
mysql> create table DemoTable1424 -> ( -> Value varchar(60) -> );
使用insert在表中插入一些记录-
mysql> insert into DemoTable1424 values('567.78483733'); mysql> insert into DemoTable1424 values('1023.45252443'); mysql> insert into DemoTable1424 values('7893322.5635543434'); mysql> insert into DemoTable1424 values('90944.665665');
使用选择显示表中的所有记录-
mysql> select * from DemoTable1424;
这将产生以下输出-
+--------------------+ | Value | +--------------------+ | 567.78483733 | | 1023.45252443 | | 7893322.5635543434 | | 90944.665665 | +--------------------+ 4 rows in set (0.00 sec)
以下是在点之前替换字符串部分的查询-
mysql> update DemoTable1424 -> set Value=concat('10000.',substring_index(Value ,'.',-1)); Rows matched: 4 Changed: 4 Warnings: 0
让我们再次检查表记录-
mysql> select * from DemoTable1424;
这将产生以下输出-
+------------------+ | Value | +------------------+ | 10000.78483733 | | 10000.45252443 | | 10000.5635543434 | | 10000.665665 | +------------------+ 4 rows in set (0.00 sec)