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

michael_roshen · August 30, 2013 · Last by michael_roshen replied at August 30, 2013 · 2687 hits

使用纯 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%'
You need to Sign in before reply, if you don't have an account, please Sign up first.