开发者

Finding out if a varchar contains a percent sign, in MySQL

开发者 https://www.devze.com 2023-02-21 10:52 出处:网络
Can\'t find an answer to this... How can I select rows where a certain column (varchar) contains a percent si开发者_如何学JAVAgn (%), in MySQL ?where col like \'%|%%\' escape \'|\'

Can't find an answer to this...

How can I select rows where a certain column (varchar) contains a percent si开发者_如何学JAVAgn (%), in MySQL ?


where col like '%|%%' escape '|'


Try this:

SELECT *
  FROM <YOUR_TABLE>
WHERE <YOUR_COLUMN> LIKE '%\%%'


I beleive if I'm not mistaken the MySql escape is the "\" character.

You could do a select like:

SELECT * FROM myTable WHERE myColumn LIKE '%\%%'


Select * from table_name
WHERE [column_name] like '%['+char(37)+']%'


If you want to use less commonly used special characters as your escape character, you can do this:

WHERE col LIKE CONCAT('%', CHAR(0), '%%') ESCAPE CHAR(0);


WHERE locate('%', col) > 0

In MSSQL CharIndex should be faster than LIKE. I haven't tested comparison between locate and LIKE in MySQL.

0

精彩评论

暂无评论...
验证码 换一张
取 消