mysql: replace \ (backslash) in strings

前端 未结 6 843
执念已碎
执念已碎 2021-01-04 11:37

I am having the following problem:

I have a table T which has a column Name with names. The names have the following structure:

A\\\\B\\C

You can cre

6条回答
  •  长情又很酷
    2021-01-04 12:01

    The literal A\\B\C must be coded as A\\\\A\\C, and the parameters of replace() need escaping too:

    select 'A\\\\B\\C', replace('A\\\\B\\C', '\\', '\\\\');
    

    output (see this running on SQLFiddle):

    A\\B\C         A\\\\B\\C
    


    So there is little point in using replace. These two statements are equivalent:

    select Name from T where Name = replace('A\\\\B\\C', '\\', '\\\\');
    select Name from T where Name =         'A\\\\B\\C';
    

提交回复
热议问题