比较MySQL中的两个字符串 [英] Compare Two Strings in MySQL

查看:131
本文介绍了比较MySQL中的两个字符串的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我当前的查询(无效)

SELECT url
FROM table
WHERE
    'http://www.longurl.com/some/string' like '%' . url . '%'

url
longurl.com

我正在尝试将longurl.com的表"中的记录与任何包含longurl.com的比较URL进行匹配.

I am trying to match the record in "table" for longurl.com to any compared URL that contains longurl.com.

应匹配比较的URL,例如:

Should match compared URLs such as:

http://www.longurl.com/some/string
http://longurl.com
http://longurl.com/some/string

在此PHP示例中,很容易进行比较:

In this PHP example, it is very easy to compare:

$url = "http://www.longurl.com/some/string";    
if(strstr($url, 'longurl.com')) {
    echo "success";
} else {
    echo "failure";
}

推荐答案

好的,关于:

SELECT url 
  FROM table 
 WHERE INSTR('http://www.longurl.com/some/string', url) > 0

(格式化在注释中效果不佳,因此我再次将其添加为答案.)

(Formatting didn't work so well in the comments, so I added it again as an answer.)

这篇关于比较MySQL中的两个字符串的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆