SQL 'LIKE' query using '%' where the search criteria contains '%'

后端 未结 8 1949
被撕碎了的回忆
被撕碎了的回忆 2020-12-03 02:29

I have an SQL query as below.

Select * from table 
where name like \'%\' + search_criteria + \'%\' 

If search_criteria = \'abc\', it will r

8条回答
  •  庸人自扰
    2020-12-03 02:59

    You need to escape it: on many databases this is done by preceding it with backslash, \%.

    So abc becomes abc\%.

    Your programming language will have a database-specific function to do this for you. For example, PHP has mysql_escape_string() for the MySQL database.

提交回复
热议问题