0

我是 MySQL 新手。我怎样才能斜线和反斜线逃脱?我想在表格中查找路径。

Path
----------------------
e:\5118\07_Live/Tools\
e:\5118/07_Live\Tools/

如何使用一个查询选择这两行?我认为它看起来像

select * from table Path e:(\|/)5118(\|/)07_Live(\|/)Tools(\|/);

我应该如何编写我的 SQL 语句?

4

1 回答 1

1
MySQL recognizes the following escape sequences.
\0  An ASCII NUL (0x00) character.
\'  A single quote (“'”) character.
\"  A double quote (“"”) character.
\b  A backspace character.
\n  A newline (linefeed) character.
\r  A carriage return character.
\t  A tab character.
\Z  ASCII 26 (Control-Z). See note following the table.
\\  A backslash (“\”) character.
\%  A “%” character. See note following the table.
\_  A “_” character. See note following the table.

所以你需要把你的查询写成

select * 
from table 
WHERE Path like  'e:\\5118\\07_Live\\Tools\\' or 
Path like  'e:/5118/07_Live/Tools/';

使用正则表达式匹配正则表达式

select id, type, details from supportContacts
where type regexp 'e:[\\/]5118[\\/]07_Live[\\/Tools[\\/]';

检查这个小提琴

于 2013-02-25T05:53:21.083 回答