Mysql-如何更新“domain.com”在“address@domain.com”中
在我的数据库中,有很多用户的电子邮件地址拼写错误。这反过来又导致我的 postfix 在发送时事通讯时退回大量邮件。
形式包括(但不限于)“yaho.com”、“yahho.com”等
很烦人!
所以我一直在尝试将这些记录更新为正确的值。
执行 select email from users where email like '%@yaho%' and email not like '%yahoo%';
并获取列表后,我陷入困境,因为我不知道如何仅更新yaho
部分。我需要完整保留用户名。
所以我想我应该转储数据库并使用 vim 替换,但我无法转义 @
符号。
顺便说一句,如何选择所有用大写字母写的电子邮件地址? select upper(email) from users;
只会将所有内容转换为大写字母,而我只需要找出已经写入大写字母的邮件。
In my database I have a lot of users who've misspelled their e-mail address. This in turn causes my postfix to bounce a lot of mails when sending the newsletter.
Forms include (but are not limited to) "yaho.com", "yahho .com" etc.
Very annoying!
So i have been trying to update those record to the correct value.
After executing select email from users where email like '%@yaho%' and email not like '%yahoo%';
and getting the list, I'm stuck because I do not know how to update only the yaho
part. I need the username to be left intact.
So I thought I would just dump the database and use vim to replace, but I cannot escape the @
symbol..
BTW, how do I select all email addresses written in CAPS? select upper(email) from users;
would just transform everything into CAPS, whereas I just needed to find out the already-written-in-CAPS mails.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(6)
您可能想尝试如下操作:
测试用例:
要回答第二个问题,您可能需要 使用区分大小写的排序规则,例如
latin1_general_cs
:测试用例:
You may want to try something like the following:
Test case:
To answer your second question, you probably need to use a case sensitive collation such as the
latin1_general_cs
:Test case:
将实时电子邮件地址更新为测试电子邮件地址
To update live email address to test email address
为了解决你的第二个问题(关于查找大写字母写的电子邮件),这样的事情可能会有所帮助:(
如果语法不完全正确,请原谅我,因为我习惯了 DB2。这个想法是将直接电子邮件地址与大写版本。)
To address your second question (about finding emails written in caps), something like this might be helpful:
(Forgive me if the syntax is not precisely correct, since I'm used to DB2. The idea is to compare the straight email address with the upper-cased version.)
您可以尝试将
INSTR
与SUBSTR
或LEFT
一起使用来获取“@”符号之前的部分。像
SELECT LEFT("[email protected]",INSTR ("[电子邮件受保护]","@")-1);
似乎有效。You could try using
INSTR
together withSUBSTR
orLEFT
to get the part before the "@" symbol, perhaps.Something like
SELECT LEFT("[email protected]",INSTR("[email protected]","@")-1);
seems to work.对于第一个问题,我会选择类似的东西
只是为了彻底,这是多字节安全的,即使我使用了
LENGTH
。所需要的只是 INSERT 的第三个参数至少与子字符串的末尾一样大。语法找到全大写电子邮件的答案是一个很好的答案。尽管您可能不会注意到差异,但执行速度可能稍快一些,但
需要更新:
BINARY(email)
来强制区分大小写的匹配。For the first question, I would choose something like
Just for the sake of being thorough, this is multi-byte safe even though I've used
LENGTH
. All that's needed is for the third argument ofINSERT
to be at least as large as the end of the substring.Syntactic's answer of finding the all-caps email is a good answer. Possibly performing slightly faster, although you would likely not notice the difference, is
Update:
BINARY(email)
is needed to force case-sensitive matching.