Ruby PG 怎么批量替换字符串?

michael_roshen · 2013年08月30日 · 最后由 michael_roshen 回复于 2013年08月30日 · 2687 次阅读

使用纯 sql 语句,怎么把电话号中 0413 替换成 024

这个查一下 pg 的语法就行了。 update table_name set field_name = regexp_replace(field_name, '^0413', '024');

#2 楼 @pongyo ok,找到了,谢谢

http://www.postgresql.org/docs/9.2/static/functions-string.html

语法:replace(string text, from text, to text)
#Replace all occurrences in string of substring from with substring to 例子:replace('abcdefabcdef', 'cd', 'XX') abXXefabXXef

update companies set contact_phone = regexp_replace(companies.contact_phone, '^0413', '024') where contact_phone  like '0413%' or mobile_phone like '0413%'
需要 登录 后方可回复, 如果你还没有账号请 注册新账号