簡體   English   中英

mysql在我的查詢中轉義特殊的四個字符

[英]mysql escape special 4 characters in my query

現在我正在測試mysql轉義特殊字符( \\,_,%,' )。

-表實際數據-

\test
_test
%test
'test

-我的查詢-

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

您可以使用如下所示的SQL LIKE運算符,該運算符最終還將與特殊字符匹配。 在這里觀看現場演示

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

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM