mysql:替换字符串中的\(反斜杠) [英] mysql: replace \ (backslash) in strings

查看:2448
本文介绍了mysql:替换字符串中的\(反斜杠)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我遇到以下问题:

我有一个表T,其中的列Name带有名称.名称具有以下结构:

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

A \\ B \ C

A\\B\C

您可以这样创建自己:

create table T ( Name varchar(10));

insert into T values ('A\\\\B\\C');

select * from T;

现在,如果我这样做:

select Name from T where Name = 'A\\B\C';

那是行不通的,我需要转义\(反斜杠):

That doesn't work, I need to escape the \ (backslash):

select Name from T where Name = 'A\\\\B\\C';

好.

但是我如何自动将其设置为字符串Name?

But how do I do this automatically to a string Name?

以下内容无法做到:

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

我得到:A\\\BC

有什么建议吗?

非常感谢.

推荐答案

您必须使用" verbatim字符串".使用该字符串后,Replace函数将 看起来像这样

You have to use "verbatim string".After using that string your Replace function will look like this

Replace(@"\", @"\\")

希望对您有帮助.

这篇关于mysql:替换字符串中的\(反斜杠)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆