MYSQL: replace()
数据库中某字段的部分内容有问题需要更正,由于业务已经上线由用户数据在内不方便重新导入。但如果手动逐条修改的话会累死个人。
查了下直接用 mysql 内建的字符串函数 replace()
可以解决问题,手册说明如下
REPLACE(str,from_str,to_str)
Returns the string str with all occurrences of the string from_str replaced by the string to_str. REPLACE() performs a case-sensitive match when searching for from_str.
mysql> SELECT REPLACE('www.mysql.com', 'w', 'Ww');
-> 'WwWwWw.mysql.com'
This function is multi-byte safe.
用法不复杂,和php /js内的方法相似
以下是执行替换的sql
UPDATE `quiz_question` SET `question`= REAPLCE(`question`, ' ', '_');
嗯,是的,就是把空格替换成下划线,因为显示在html中空格会被忽略掉,导致填空位置显示不清晰。
一句sql省下用python/php 取出来再重新写入的功夫。
PEACE!