Warning: file_get_contents(/data/phpspider/zhask/data//catemap/8/mysql/60.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181

Warning: file_get_contents(/data/phpspider/zhask/data//catemap/5/sql/69.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
替换mysql中两个字符之间的文本_Mysql_Sql - Fatal编程技术网

替换mysql中两个字符之间的文本

替换mysql中两个字符之间的文本,mysql,sql,Mysql,Sql,我需要替换mysql表中一列中两个特定字符之间的文本。 例如,在我的“email”栏中,我想将“@gmail.com”中的“gmail”替换为“yahoo”。 也就是说,在“@”和“.”之间查找文本,并替换该文本。 以下是我尝试过的: UPDATE users SET email= REPLACE (email, '%@%.%', 'test') WHERE email LIKE %@%.%; 我认为这种通配符只在WHERE子句中使用。如何将其放入REPLACE()函数中? 非常感谢您的帮助。

我需要替换mysql表中一列中两个特定字符之间的文本。 例如,在我的“email”栏中,我想将“@gmail.com”中的“gmail”替换为“yahoo”。 也就是说,在“@”和“.”之间查找文本,并替换该文本。 以下是我尝试过的:

UPDATE users
SET email= REPLACE (email, '%@%.%', 'test')
WHERE email LIKE %@%.%;
我认为这种通配符只在WHERE子句中使用。如何将其放入REPLACE()函数中? 非常感谢您的帮助。谢谢。

如果您想将“@gmail.”替换为“@yahoo.”,只需执行以下操作:

UPDATE users
    SET email = REPLACE(email, '@gmail.', '@yahoo.')
WHERE email LIKE '%@gmail.%';
如果您希望域名始终为gmail,那么您可以尝试重建电子邮件:

UPDATE users
    SET email = CONCAT(substring_index(email, '@', 1), '@',
                       'yahoo',
                       substring_index(email, '.', -1)
                      )
    WHERE email LIKE '%@%.%';
这并不是100%准确——当
电子邮件中有多个“@”或“.”时,您的问题是未定义的。但它可能会满足你的需要