Finding out if a varchar contains a percent sign, in MySQL
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.
精彩评论