How to use a percent (%) in a LIKE without it being treated as a wildcard?

瘦欲@ 提交于 2019-12-19 06:58:31

问题


I have a database that is supposed to contain all top-level and second-level domain names. But the feed I'm parsing contains a lot of sub folders, I'd like to delete any row that contains any % sign in it, but I am having a hard time figuring out how to use a percent sign as the field I'd like to match, while still using the LIKE feature. Below is the code I'm trying to use:

select FROM `001ProductList` WHERE programURL  LIKE '%%%'

Here is an example of what I'm trying to match:

www.site.com%3Ack-5941560-10463497?url=http%3A%2F%2Fwww.example.com%2Fproddetail.aspx%...

If I encounter a row with a % sign in it, I want to delete it.


回答1:


Escape the literal % character:

select * 
FROM 001ProductList
WHERE programURL LIKE '%\%%'

or use regex

WHERE programURL RLIKE '%'



回答2:


You may use the LOCATE function, like so:

SELECT * 
FROM `001ProductList`
WHERE LOCATE('%', `programURL`) <> 0;


来源:https://stackoverflow.com/questions/19749787/how-to-use-a-percent-in-a-like-without-it-being-treated-as-a-wildcard

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!