我的表格中有几个gmail地址
foobarbaz@gmail.com
foo.bar.baz@gmail.com
foobar.baz@gmail.com
foo.barbaz@gmail.com
我需要替换包含符号'的地址gmail。' 得到:
foobarbaz@gmail.com
foobarbaz@gmail.com
foobarbaz@gmail.com
foobarbaz@gmail.com
我的查询不起作用
UPDATE voters set email
replace(substring(email, 1, LOCATE('@', email) -1), '.', '')
WHERE email REGEXP '@googlemail.com|@gmail.com'
请帮忙,谢谢!
答案 0 :(得分:1)
您在@
之前提取子字符串并替换了点,但在执行此操作后,您不会在@
之后添加子字符串:
UPDATE voters
SET email = CONCAT(replace(substring(email, 1, LOCATE('@', email) -1), '.', ''),
SUBSTRING(email, LOCATE('@', email)))
WHERE email REGEXP '@googlemail.com|@gmail.com'
答案 1 :(得分:0)
您可以使用substring_index&和&amp ;; substring:
UPDATE table1
SET email = CONCAT (
replace(substring_index(email, '@', 1), '.', '')
,substring(email, instr(email, '@'))
)
WHERE substring_index(email, '@', -1) IN (
'googlemail.com'
,'gmail.com'
);