简体   繁体   中英

mysql escape special 4 characters in my query

now i'm testing mysql escape special characters( \\,_,%,' ).

-table real data-

\test
_test
%test
'test

-my query-

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 '''

but just first query is success result. and just multiple escape was not running

  • multiple escape query -

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

please advise for my query. and i want to [insert value] just 4 case. (for example, under the 4 insert value not test case.

 \\test
 \_test
 \%test
 \'test

)

You can use SQL LIKE operator like below which will eventually match the special characters as well. See a Live Demo Here

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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM