2015-09-11 31 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

一個搜索輸入 - >一個搜索結果。 –