Skip to content

POSTGRESQL-字符串替换

sql
#查看修改后结果,并不真实修改数据库
select replace(字段名,'被替换内容','需要替换的内容') from 表名 where 字段名 like E'%被替换内容%';

#更改字段中包含某个字符为另一个字符,这里是把'被替换内容'替换为需要替换的内容。
update 表名 set 字段名=replace(字段名,E'被替换内容','需要替换的内容') where 字段名 like E'%被替换内容%';
#查看修改后结果,并不真实修改数据库
select replace(字段名,'被替换内容','需要替换的内容') from 表名 where 字段名 like E'%被替换内容%';

#更改字段中包含某个字符为另一个字符,这里是把'被替换内容'替换为需要替换的内容。
update 表名 set 字段名=replace(字段名,E'被替换内容','需要替换的内容') where 字段名 like E'%被替换内容%';
sql
update phpg_nbphs.hd_statistics_index
set index_rule=replace(index_rule, E'迁出', '外迁')
where id in (162, 163, 164, 167, 168, 170) and index_rule like E'%迁出%';
update phpg_nbphs.hd_statistics_index
set index_rule=replace(index_rule, E'迁出', '外迁')
where id in (162, 163, 164, 167, 168, 170) and index_rule like E'%迁出%';