如何在SQL语句中使用或运算符?

时间:2013-02-25 05:34:51

标签: mysql sql perl

我是MySQL新手。我怎么能减少和反斜杠逃脱?我想在表格中找到路径。

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

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

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

我应该如何编写SQL语句?

1 个答案:

答案 0 :(得分: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[\\/]';

选中此fiddle