2015-09-11 36 views
0

现在我正在测试mysql转义特殊字符(\,_,%,')。在我的查询中mysql转义特殊4个字符

-table真实DATA-

\test 
_test 
%test 
'test 

-My查询 -

1.

select * from user_name where user_name LIKE '\test%' escape '|' 

2.

select * from user_name where user_name LIKE '_test%' escape '_' (underscope) 

3.

select * from user_name where user_name LIKE '%test%' escape '%' 

4.

select * from user_name where user_name LIKE ''test%' escape ''' 

只是第一个查询是成功的结果。和刚刚逃生的多个未运行

  • 多个逃避查询 -

    select * from user_name where user_name = '\test%' escape ('|' || '%' || '_' || ''') 
    

请告知我的查询。我想[插入价值]只有4例。 (例如,4插入值下没有测试的情况下。

\\test 
\_test 
\%test 
\'test 

+0

请不要格式化你的代码 – e4c5

+0

在** **什么语言? –

+0

现在我只是在MySQL WorkBank中测试mysql查询 –

回答

0

您可以使用SQL LIKE运营商像下面这将最终匹配的特殊字符为好。看到Live Demo Here

select * from user_name where user_name LIKE '%test%' 
+0

@MinSubso,使用MySQL中的'LIKE'运算符。查看演示http://sqlfiddle.com/#!9/41a0e/2 – Rahul

+0

谢谢。现在我正在测试你的演示链接。但我想要真实的数据。如果表数据[%test],搜索查询结果只有一个[%test]。 –

+0

一个搜索输入 - >一个搜索结果。 –