Mysql 在更新记录时,我们可以在sql中的replace函数中使用string函数吗

Mysql 在更新记录时,我们可以在sql中的replace函数中使用string函数吗,mysql,sql,replace,concat,Mysql,Sql,Replace,Concat,我想在某些情况下更新我的记录 我有一个列ResidencedDress1,其中包含电子邮件id和地址 样本数据: sap3200@gmail.com,Rourkela sap3212@gmail.com 2nd street,7 hills 2nd street, sap3212@gmail.com 我通过以下方式找到来自ResidencedDress1的电子邮件: select (concat(trim(substring_index(substring_index(Resid

我想在某些情况下更新我的记录

我有一个列ResidencedDress1,其中包含电子邮件id和地址

样本数据:

sap3200@gmail.com,Rourkela   
sap3212@gmail.com 2nd street,7 hills    
2nd street, sap3212@gmail.com
我通过以下方式找到来自ResidencedDress1的电子邮件:

select (concat(trim(substring_index(substring_index(Residence_Address1, '@', '1'), ' ', -1)),'','@gmail.com') as mail,Residence_Address1
from mytable
where Residence_Address1 like '%gmail%' and Email_Personal1=""  
update mytable
set email_Personal1=concat(trim(substring_index(substring_index(Residence_Address1, '@', '1'), ' ', -1)), '','@gmail.com') , 
                 Residence_Address1=replace(residence_address1,"'concat(trim(substring_index(substring_index(Residence_Address1, '@', '1'), ' ', -1)), '','@gmail.com')'",'')
where Residence_Address1 like '%gmail%' and Email_Personal1=""
当我以这种方式更新它时:

select (concat(trim(substring_index(substring_index(Residence_Address1, '@', '1'), ' ', -1)),'','@gmail.com') as mail,Residence_Address1
from mytable
where Residence_Address1 like '%gmail%' and Email_Personal1=""  
update mytable
set email_Personal1=concat(trim(substring_index(substring_index(Residence_Address1, '@', '1'), ' ', -1)), '','@gmail.com') , 
                 Residence_Address1=replace(residence_address1,"'concat(trim(substring_index(substring_index(Residence_Address1, '@', '1'), ' ', -1)), '','@gmail.com')'",'')
where Residence_Address1 like '%gmail%' and Email_Personal1=""

这样,它会更新email_personal1,但不会用替换的空值(而不是该行中的gmail id值)更新residence_address1。我错在哪里了?

您可以在
更新中更新多列并混合字符串函数。在这个问题中,你有额外的双引号,这是不需要的。也许你打算这样做:

update fulldata_table
    set email_Personal1 = concat(trim(substring_index(substring_index(Residence_Address1, '@', '1'
                                       ), ' ', -1)
       ), '', '@gmail.com'), 
        Residence_Address1 = replace(residence_address1, concat(trim(substring_index(substring_index(Residence_Address1, '@', '1'), ' ', -1)), '', '@gmail.com', '')
    where Residence_Address1 like '%gmail%' and Email_Personal1 = ''

您可以在
更新中更新多列和混合字符串函数。在这个问题中,你有额外的双引号,这是不需要的。也许你打算这样做:

update fulldata_table
    set email_Personal1 = concat(trim(substring_index(substring_index(Residence_Address1, '@', '1'
                                       ), ' ', -1)
       ), '', '@gmail.com'), 
        Residence_Address1 = replace(residence_address1, concat(trim(substring_index(substring_index(Residence_Address1, '@', '1'), ' ', -1)), '', '@gmail.com', '')
    where Residence_Address1 like '%gmail%' and Email_Personal1 = ''
试试这个:

UPDATE fulldata_table SET
  email_Personal1 = concat(trim(substring_index(substring_index(Residence_Address1, '@', '1'),' ',-1 ) ), '@gmail.com') ,
  Residence_Address1 = replace( residence_address1, concat( trim( substring_index( substring_index(Residence_Address1, '@', '1'), ' ', -1 ) ), '@gmail.com', '' ), '' )
WHERE Residence_Address1 LIKE '%gmail%' AND Email_Personal1 = '';
试试这个:

UPDATE fulldata_table SET
  email_Personal1 = concat(trim(substring_index(substring_index(Residence_Address1, '@', '1'),' ',-1 ) ), '@gmail.com') ,
  Residence_Address1 = replace( residence_address1, concat( trim( substring_index( substring_index(Residence_Address1, '@', '1'), ' ', -1 ) ), '@gmail.com', '' ), '' )
WHERE Residence_Address1 LIKE '%gmail%' AND Email_Personal1 = '';

谢谢但它给了我语法错误。通常,对于replace函数,语法是:replace(字段名,'string需要被替换,'replace with this'),即replace(字段名,'string1','string2')。那么我是否需要将整个第二部分从concat开始放在单引号中?在替换的第二部分中设置单引号时,它看起来非常复杂。这就是为什么我在第二部分添加了双引号。@iks_in。你不能那样使用双引号。谢谢。但它给了我语法错误。通常,对于replace函数,语法是:replace(字段名,'string需要被替换,'replace with this'),即replace(字段名,'string1','string2')。那么我是否需要将整个第二部分从concat开始放在单引号中?在替换的第二部分中设置单引号时,它看起来非常复杂。这就是为什么我在第二部分添加了双引号。@iks_in。你不能那样使用双引号。谢谢。但它返回了13401行中的12388行。对于剩余的1013行,它不起作用。这些行可能被where子句排除在外。您可以通过运行以下命令来检查这些情况,以及它们不适合的原因:
select*from fulldata_table where not(住宅地址1,如“%gmail%”和电子邮件地址1=”谢谢。但它返回了13401行中的12388行。对于剩余的1013行,它不起作用。这些行可能被where子句排除在外。您可以通过运行以下命令来检查这些情况,以及它们不适合的原因:
select*from fulldata_table where not(住宅地址1,如“%gmail%”和电子邮件地址1=”