ID URL
1 www.163.com/11111
2 www.163.com/22222
3 www.163.com/33333
要将URL中下划线 www.163.com 的部分修改为 www.165.com ,后面的不变,修改后的结果如下:
ID URL
1 www.165.com/11111
2 www.165.com/22222
3 www.165.com/33333
这种要怎么做??
5 个解决方案
#1
自己搞定啦:
UPDATE test SET url=REPLACE(url,'www.163.com','www.165.com');
UPDATE 表名 SET 字段=REPLACE(字段,'要替换的字符串','替换后的字符串');
UPDATE test SET url=REPLACE(url,'www.163.com','www.165.com');
UPDATE 表名 SET 字段=REPLACE(字段,'要替换的字符串','替换后的字符串');
#2
用 replace 就行了。
#3
#4
update tb set url=replace(url,'www.163.com','www.165.com');
#5
对,用函数替换就好
update tb set url=replace(url,'www.163.com','www.165.com');
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
update tb set url=replace(url,'www.163.com','www.165.com');
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
#1
自己搞定啦:
UPDATE test SET url=REPLACE(url,'www.163.com','www.165.com');
UPDATE 表名 SET 字段=REPLACE(字段,'要替换的字符串','替换后的字符串');
UPDATE test SET url=REPLACE(url,'www.163.com','www.165.com');
UPDATE 表名 SET 字段=REPLACE(字段,'要替换的字符串','替换后的字符串');
#2
用 replace 就行了。
#3
#4
update tb set url=replace(url,'www.163.com','www.165.com');
#5
对,用函数替换就好
update tb set url=replace(url,'www.163.com','www.165.com');
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
update tb set url=replace(url,'www.163.com','www.165.com');
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